nskeyedarchiver

Encode NSArray or NSDictionary using NSCoder

断了今生、忘了曾经 提交于 2019-11-28 08:19:52
I was wondering whether or not it is possible to use the NSCoder method: - (void)encodeObject:(id)objv forKey:(NSString *)key to encode either an instance of NSArray or NSDictionary. If not how do you go about encoding them? I am trying to use NSKeyedArchived / NSKeyedUnarchiver to send data between phones using GameKit. I tried it and cannot seem to retrieve the string I stored in my array. The packet class I made comes through along with the packet type integer, but not the data in the array it seems. Thanks in advance! NSKeyedArchiver/Unarchiver should encode and decode NSArrays and

Serialization vs. Archiving?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 03:53:45
问题 The iOS docs differentiate between "serializing" and "archiving." Is this a general distinction (i.e., holds in other languages) or is it specific to Objective-C? Also, what is the difference between these two? 回答1: This is a case of one being the other some (but not all) of the time. Wikipedia has this to say about serialization: "Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted

Saving [UIColor colorWithPatternImage:image] UIColor to Core Data using NSKeyedArchiver

霸气de小男生 提交于 2019-11-27 15:24:19
I'm unable to create an NSData object from a UIColor (with a pattern) created with the factory method [UIColor colorWithPatternImage:image] works fine for standard UIColor objects. Wondering if there is another way to save a UIColor with a pattern into Core Data. I am using the following code to archive the UIColor (with a pattern)... - (id)transformedValue:(id)value { NSData *data = [NSKeyedArchiver archivedDataWithRootObject:value]; return data; } and these are the errors I'm receiving... -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding

Save and retrieve value via KeyChain

一曲冷凌霜 提交于 2019-11-27 11:51:22
I'm trying to store an Integer and retrieve it using KeyChain. This is how I save it: func SaveNumberOfImagesTaken() { let key = "IMAGE_TAKEN" var taken = 10 let data = NSKeyedArchiver.archivedDataWithRootObject(taken) let query : [String:AnyObject] = [ kSecClass as String : kSecClassGenericPassword, kSecAttrAccount as String : key, kSecValueData as String : data ] let status : OSStatus = SecItemAdd(query as CFDictionaryRef, nil) } This is how I try to retrieve it: func CheckIfKeyChainValueExitss() -> AnyObject? { var key = "IMAGE_TAKEN" let query : [String:AnyObject] = [ kSecClass as String :

Swift structs to NSData and back

匆匆过客 提交于 2019-11-27 08:39:14
I have a struct containing a struct and an NSObject that I want to serialize into an NSData object: struct Packet { var name: String var index: Int var numberOfPackets: Int var data: NSData } var thePacket = Packet(name: name, index: i, numberOfPackets: numberOfPackets, data: packetData) How do I best serialize the Packet into an NSData , and how do I best deserialize it? Using var bufferData = NSData(bytes: & thePacket, length: sizeof(Packet)) of only gives me the pointers of name and data. I was exploring NSKeyedArchiver , but then I'd have to make Packet an object, and I'd prefer to keep it

How do I save a UIColor with UserDefaults? [duplicate]

本秂侑毒 提交于 2019-11-27 05:35:25
This question already has an answer here: Saving UIColor to and loading from NSUserDefaults 8 answers I'm trying to program my code so that if the user presses the Night Button the background will turn black and stay black if the user closes the app. (Same goes for day mode.) Please note: I already coded buttons and when they press it, all of the scenes change to that mode. Here's my code where I'm going going to need the background color to be saved: (I need it in both if statements) if GlobalData.dayBool == true && GlobalData.night == false { backgroundColor = GlobalData.dayColor } if

Simple persistent storage in Swift

拟墨画扇 提交于 2019-11-27 02:44:45
问题 I have an array of objects each with a number of properties. Here is some sample data taken by looping through the array of objects: Name = Rent Default Value 750 This Months Estimate = 750 Sum Of This Months Actuals = 0 Risk Factor = 0.0 Monthly Average = 750.0 -------------- Name = Bills Default Value 250 This Months Estimate = 170 Sum Of This Months Actuals = 140 Risk Factor = 0.0 Monthly Average = 190.0 -------------- Name = Food Default Value 240 This Months Estimate = 200 Sum Of This

Saving [UIColor colorWithPatternImage:image] UIColor to Core Data using NSKeyedArchiver

∥☆過路亽.° 提交于 2019-11-26 17:08:40
问题 I'm unable to create an NSData object from a UIColor (with a pattern) created with the factory method [UIColor colorWithPatternImage:image] works fine for standard UIColor objects. Wondering if there is another way to save a UIColor with a pattern into Core Data. I am using the following code to archive the UIColor (with a pattern)... - (id)transformedValue:(id)value { NSData *data = [NSKeyedArchiver archivedDataWithRootObject:value]; return data; } and these are the errors I'm receiving... -

Swift structs to NSData and back

大憨熊 提交于 2019-11-26 14:14:29
问题 I have a struct containing a struct and an NSObject that I want to serialize into an NSData object: struct Packet { var name: String var index: Int var numberOfPackets: Int var data: NSData } var thePacket = Packet(name: name, index: i, numberOfPackets: numberOfPackets, data: packetData) How do I best serialize the Packet into an NSData , and how do I best deserialize it? Using var bufferData = NSData(bytes: & thePacket, length: sizeof(Packet)) of only gives me the pointers of name and data.

How do I save a UIColor with UserDefaults? [duplicate]

微笑、不失礼 提交于 2019-11-26 11:37:58
问题 This question already has answers here : Saving UIColor to and loading from NSUserDefaults (8 answers) Closed 3 years ago . I\'m trying to program my code so that if the user presses the Night Button the background will turn black and stay black if the user closes the app. (Same goes for day mode.) Please note: I already coded buttons and when they press it, all of the scenes change to that mode. Here\'s my code where I\'m going going to need the background color to be saved: (I need it in