nscoding

iPhone - Why does the documentation say UIImageView is NSCoding compliant?

这一生的挚爱 提交于 2019-11-28 18:55:40
Ideally an NSCoding compliant class will work as expected using encodeWithCoder: and initWithCoder: (at least I thought so till recently) without the developer having to bother about what goes on inside the routines (unless my idea of an NSCoding compliant class are totally screwed up!) The UIImageView class is NSCoding compliant. So I should not have to bother how it will be serialized/de-serialized using the NSKeyedArchiver and NSKeyedUnarchiver classes. But every time I try and encode a UIImageView object, I get an error that UIImage does not recognize encodeWithCoder: method. Now the

How can I get an NSCoder to encode/decode a Swift array of structs?

主宰稳场 提交于 2019-11-28 06:30:45
问题 I have an object that must conform to NSCoding and that holds an array of UInt64 values. How can I encode/decode it with an NSCoder at all? Bonus question: how can I encode it most compactly? (It has to go into saved Game Center state data, whose size is limited.) Ideally, I just want to write an Int which is the size n of the array, and then write n times the 64 bits of a UInt64 , and read it similarly. Can I do this? coder.encodeObject(values, forKey: "v") doesn't work. class MyObject:

Converting CLLocationCoordinate2D to a String that can be stored

被刻印的时光 ゝ 提交于 2019-11-28 04:44:27
问题 I'm trying to save the coordinates of a user while in one ViewController so that it can be used to create an Annotation that can displayed in another ViewController. In the view controller that stores the coordinates I'm using the code NSUserDefaults.standardUserDefaults().setObject( Location, forKey: "Location") In the map view controller that displays the annotation I'm trying to get the coordinates using the code let Location = NSUserDefaults.standardUserDefaults().stringForKey("Location")

NSCoding VS Core data

帅比萌擦擦* 提交于 2019-11-28 04:24:05
I've been searching for an article that explains NSCoding (NSKeyedArchiver...) advantages and disadvantages over use of CoreData (SQLite....). There's a lot of options, I can implement my own custom binary reader/writer, or use plists/xml/json... or use SQLite or NSCoding. I'm kind of lost right now. Can any body explain what's the difference between the MAIN features? It depends which kind of data you want to save and whether you will use it only internally or you have to exchange the data with an external service. NSCoding is generally speaking a data serializer. A lot of built-in objects

Swift encode tuple using NSCoding

落花浮王杯 提交于 2019-11-28 00:26:43
问题 Is it possible to store a tuple using NSCoding ? I have a tuple like ((UInt8, UInt8), (UInt8, UInt8)) . But aCoder.encodeObject(myTuple) doesn't work. Do I have to convert the tuple into NSData or is this absolutely not possible? Thanks for any help 回答1: Tuple cannot be encoded because it is not a class, but one approach is to encode each component of a tuple separately and then upon decoding you decode each component and then set the value of the tuple to a tuple constructed from the decoded

Write custom object to .plist in Cocoa

◇◆丶佛笑我妖孽 提交于 2019-11-27 22:34:01
I am blocking into something and I am sure it is too big. I have a custom object that look like this @interface DownloadObject : NSObject <NSCoding>{ NSNumber *key; NSString *name; NSNumber *progress; NSNumber *progressBytes; NSNumber *size; NSString *path; } @property (copy) NSNumber *key; @property (copy) NSString *name; @property (copy) NSNumber *progress; @property (copy) NSNumber *size; @property (copy) NSString *path; @property (copy) NSNumber *progressBytes; -(id)initWithKey:(NSNumber *)k name:(NSString *)n progress:(NSNumber *)pro size:(NSNumber *)s path:(NSString *)p progressBytes:

Got Unrecognized selector -replacementObjectForKeyedArchiver: crash when implementing NSCoding in Swift

泄露秘密 提交于 2019-11-27 19:13:10
I created a Swift class that conforms to NSCoding. (Xcode 6 GM, Swift 1.0) import Foundation private var nextNonce = 1000 class Command: NSCoding { let nonce: Int let string: String! init(string: String) { self.nonce = nextNonce++ self.string = string } required init(coder aDecoder: NSCoder) { nonce = aDecoder.decodeIntegerForKey("nonce") string = aDecoder.decodeObjectForKey("string") as String } func encodeWithCoder(aCoder: NSCoder) { aCoder.encodeInteger(nonce, forKey: "nonce") aCoder.encodeObject(string, forKey: "string") } } But when I call... let data = NSKeyedArchiver

Got Unrecognized selector -replacementObjectForKeyedArchiver: crash when implementing NSCoding in Swift

半世苍凉 提交于 2019-11-27 04:21:31
问题 I created a Swift class that conforms to NSCoding. (Xcode 6 GM, Swift 1.0) import Foundation private var nextNonce = 1000 class Command: NSCoding { let nonce: Int let string: String! init(string: String) { self.nonce = nextNonce++ self.string = string } required init(coder aDecoder: NSCoder) { nonce = aDecoder.decodeIntegerForKey("nonce") string = aDecoder.decodeObjectForKey("string") as String } func encodeWithCoder(aCoder: NSCoder) { aCoder.encodeInteger(nonce, forKey: "nonce") aCoder

NSCoding VS Core data

女生的网名这么多〃 提交于 2019-11-27 00:22:57
问题 I've been searching for an article that explains NSCoding (NSKeyedArchiver...) advantages and disadvantages over use of CoreData (SQLite....). There's a lot of options, I can implement my own custom binary reader/writer, or use plists/xml/json... or use SQLite or NSCoding. I'm kind of lost right now. Can any body explain what's the difference between the MAIN features? 回答1: It depends which kind of data you want to save and whether you will use it only internally or you have to exchange the

Write custom object to .plist in Cocoa

对着背影说爱祢 提交于 2019-11-26 23:11:28
问题 I am blocking into something and I am sure it is too big. I have a custom object that look like this @interface DownloadObject : NSObject <NSCoding>{ NSNumber *key; NSString *name; NSNumber *progress; NSNumber *progressBytes; NSNumber *size; NSString *path; } @property (copy) NSNumber *key; @property (copy) NSString *name; @property (copy) NSNumber *progress; @property (copy) NSNumber *size; @property (copy) NSString *path; @property (copy) NSNumber *progressBytes; -(id)initWithKey:(NSNumber