Class: NSKeyedArchiver
Overview
NSKeyedArchiver, a concrete subclass of NSCoder, provides a way to encode objects (and scalar values) into an architecture-independent format that can be stored in a file. When you archive a set of objects, the class information and instance variables for each object are written to the archive. NSKeyedArchiver’s companion class, NSKeyedUnarchiver, decodes the data in an archive and creates a set of objects equivalent to the original set.
Class Method Summary (collapse)
-
+ archivedDataWithRootObject:
Returns an NSData object containing the encoded form of the object graph whose root object is given.
-
+ archiveRootObject:toFile:
Archives an object graph rooted at a given object by encoding it into a data object then atomically writes the resulting data object to a file at a given path, and returns a Boolean value that indicates whether the operation was successful.
-
+ classNameForClass:
Returns the class name with which NSKeyedArchiver encodes instances of a given class.
-
+ setClassName:forClass:
Adds a class translation mapping to NSKeyedArchiver whereby instances of of a given class are encoded with a given class name instead of their real class names.
Instance Method Summary (collapse)
-
- classNameForClass:
Returns the class name with which the receiver encodes instances of a given class.
-
- delegate
Returns the receiver’s delegate.
-
- encodeBool:forKey:
Encodes a given Boolean value and associates it with a given key.
-
- encodeBytes:length:forKey:
Encodes a given number of bytes from a given C array of bytes and associates them with the a given key.
-
- encodeConditionalObject:forKey:
Encodes a reference to a given object and associates it with a given key only if it has been unconditionally encoded elsewhere in the archive with encodeObject:forKey:.
-
- encodeDouble:forKey:
Encodes a given double value and associates it with a given key.
-
- encodeFloat:forKey:
Encodes a given float value and associates it with a given key.
-
- encodeInt32:forKey:
Encodes a given 32-bit integer value and associates it with a given key.
-
- encodeInt64:forKey:
Encodes a given 64-bit integer value and associates it with a given key.
-
- encodeInt:forKey:
Encodes a given int value and associates it with a given key.
-
- encodeObject:forKey:
Encodes a given object and associates it with a given key.
-
- finishEncoding
Instructs the receiver to construct the final data stream.
-
- initForWritingWithMutableData:
Returns the receiver, initialized for encoding an archive into a given a mutable-data object.
-
- outputFormat
Returns the format in which the receiver encodes its data.
-
- setClassName:forClass:
Adds a class translation mapping to the receiver whereby instances of of a given class are encoded with a given class name instead of their real class names.
-
- setDelegate:
Sets the delegate for the receiver.
-
- setOutputFormat:
Sets the format in which the receiver encodes its data.
Methods inherited from NSCoder
#allowedClasses, #allowsKeyedCoding, #containsValueForKey:, #decodeArrayOfObjCType:count:at:, #decodeBoolForKey:, #decodeBytesForKey:returnedLength:, #decodeBytesWithReturnedLength:, #decodeDataObject, #decodeDoubleForKey:, #decodeFloatForKey:, #decodeInt32ForKey:, #decodeInt64ForKey:, #decodeIntForKey:, #decodeIntegerForKey:, #decodeObject, #decodeObjectForKey:, #decodeObjectOfClass:forKey:, #decodeObjectOfClasses:forKey:, #decodePropertyListForKey:, #decodeValueOfObjCType:at:, #decodeValuesOfObjCTypes:, #encodeArrayOfObjCType:count:at:, #encodeBycopyObject:, #encodeByrefObject:, #encodeBytes:length:, #encodeConditionalObject:, #encodeDataObject:, #encodeInteger:forKey:, #encodeObject:, #encodeRootObject:, #encodeValueOfObjCType:at:, #encodeValuesOfObjCTypes:, #objectZone, #requiresSecureCoding, #setObjectZone:, #systemVersion, #versionForClassName:
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (NSData) archivedDataWithRootObject(rootObject)
Returns an NSData object containing the encoded form of the object graph whose root object is given.
+ (Boolean) archiveRootObject(rootObject, toFile:path)
Archives an object graph rooted at a given object by encoding it into a data object then atomically writes the resulting data object to a file at a given path, and returns a Boolean value that indicates whether the operation was successful. The format of the archive is NSPropertyListBinaryFormat_v1_0.
+ (String) classNameForClass(cls)
Returns the class name with which NSKeyedArchiver encodes instances of a given class.
+ (Object) setClassName(codedName, forClass:cls)
Adds a class translation mapping to NSKeyedArchiver whereby instances of of a given class are encoded with a given class name instead of their real class names. When encoding, the class’s translation mapping is used only if no translation is found first in an instance’s separate translation map.
Instance Method Details
- (String) classNameForClass(cls)
Returns the class name with which the receiver encodes instances of a given class.
- (Object) delegate
Returns the receiver’s delegate.
- (Object) encodeBool(boolv, forKey:key)
Encodes a given Boolean value and associates it with a given key.
- (Object) encodeBytes(bytesp, length:lenv, forKey:key)
Encodes a given number of bytes from a given C array of bytes and associates them with the a given key.
- (Object) encodeConditionalObject(objv, forKey:key)
Encodes a reference to a given object and associates it with a given key only if it has been unconditionally encoded elsewhere in the archive with encodeObject:forKey:.
- (Object) encodeDouble(realv, forKey:key)
Encodes a given double value and associates it with a given key.
- (Object) encodeFloat(realv, forKey:key)
Encodes a given float value and associates it with a given key.
- (Object) encodeInt32(intv, forKey:key)
Encodes a given 32-bit integer value and associates it with a given key.
- (Object) encodeInt64(intv, forKey:key)
Encodes a given 64-bit integer value and associates it with a given key.
- (Object) encodeInt(intv, forKey:key)
Encodes a given int value and associates it with a given key.
- (Object) encodeObject(objv, forKey:key)
Encodes a given object and associates it with a given key.
- (Object) finishEncoding
Instructs the receiver to construct the final data stream. No more values can be encoded after this method is called. You must call this method when finished.
- (Object) initForWritingWithMutableData(data)
Returns the receiver, initialized for encoding an archive into a given a mutable-data object. When you finish encoding data, you must invoke finishEncoding at which point data is filled. The format of the receiver is NSPropertyListBinaryFormat_v1_0.
- (NSPropertyListFormat) outputFormat
Returns the format in which the receiver encodes its data.
- (Object) setClassName(codedName, forClass:cls)
Adds a class translation mapping to the receiver whereby instances of of a given class are encoded with a given class name instead of their real class names. When encoding, the receiver’s translation map overrides any translation that may also be present in the class’s map.
- (Object) setDelegate(delegate)
Sets the delegate for the receiver.
- (Object) setOutputFormat(format)
Sets the format in which the receiver encodes its data.