nscoding

Strange behavoir when decoding an NSArray via NSSecureCoding

允我心安 提交于 2019-12-04 04:42:14
i spent all afternoon banging my head against the wall trying to figure out why decoding of this class was failing. the class has a property that is an NSArray of Foo objects. Foo conforms to NSSecureCoding, and i have successfully encoded and decoded that class by itself. i was getting an error in initWithCoder: that said failed to decode class Foo. through some experimentation, i discovered that i needed to add [Foo class] to initWithCoder: in order for it to work. maybe this will help someone else who's having the same problem. my question is, why is this necessary? i found no suggestion

Overridden == function for Equatable type not called for custom class that subclasses NSCoding and NSObject [duplicate]

↘锁芯ラ 提交于 2019-12-03 22:51:36
This question already has answers here : Closed 3 years ago . NSObject subclass in Swift: hash vs hashValue, isEqual vs == (2 answers) The FooBar class below has to override the == function of the Equatable type. However, calling contains on an array of FooBar objects does not cause a breakpoint inside the custom == function to get invoked. Is it possible another == function is overriding this custom one? Note: Because FooBar must subclass from NSCoding and NSObject, FooBar does not list Equatable as a protocol because it causes this error: Redundant conformance of 'FooBar' to protocol

How do I using NSCoding for a c-array of structs? (MKPolyline)

坚强是说给别人听的谎言 提交于 2019-12-03 21:10:11
I want to add NSCoding support to an c array of structs. Specifically this is for a subclass of MKPolyline , i.e. this is what I have to work with: @property (nonatomic, readonly) MKMapPoint *points; @property (nonatomic, readonly) NSUInteger pointCount; + (MKPolyline *)polylineWithPoints:(MKMapPoint *)points count:(NSUInteger)count; I found a good answer on how to encode a individual struct . E.g. NSValue* point = [NSValue value:&aPoint withObjCType:@encode(MKMapPoint)]; [aCoder encodeObject:point forKey:@"point"]; .... NSValue* point = [aDecoder decodeObjectForKey:@"point"];

Adding NSCoding as an Extension

房东的猫 提交于 2019-12-03 16:54:20
问题 I'd like to extend a framework class ( I don't want to edit the source code directly ), and make it conform to NSCoding . Basically, here's a simplification of the situation I'm in : /* Can't be edited. */ class Car: NSObject { var color: String? } /* Can be edited */ extension Car: NSCoding { init(coder aDecoder: NSCoder) { } func encodeWithCoder(aCoder: NSCoder) { } } The issue is init(coder aDecoder: NSCoder) is, as per the header file, a designated initializer ( isn't this weird though ?

Saving PFObject NSCoding

余生长醉 提交于 2019-12-03 12:52:53
My Problem: saveInBackground isn't working. The Reason It's not working: I'm saving PFObjects stored in an NSArray to file using NSKeyedArchiving . The way I do that is by implementing NSCoding via this library . For some reason unknown to me, several other fields are being added and are set to NULL. I have a feeling that this is screwing up the API call to saveInBackground . When I call saveInBackground on the first set of objects (before NSKeyedArchiving ) saveInBackground works just fine. However, when I call it on the second object (after NSKeyedArchiving ) it does not save. Why is this?

Inspecting files of type “NeXT/Apple typedstream” version 4 (NSArchiver)

有些话、适合烂在心里 提交于 2019-12-03 10:01:36
问题 For a data recovery program I need to be able to extract the values+types from files written by NSArchiver, without having access to Apple's CF / NS frameworks. The OS X file command reports such files as: NeXT/Apple typedstream data, little endian, version 4, system 1000 Is there any documentation on how these files are encoded, or has anyone come up with code that can parse them? Here's an example of such data (also: downloadable): 04 0B 73 74 72 65 61 6D 74 79 70 65 64 81 E8 03 .

When to use NSSecureCoding

☆樱花仙子☆ 提交于 2019-12-03 09:34:30
I'm learning about the NSSecureCoding protocol introduced by Apple in iOS 6. From my understanding so far, it should be used whenever a class encodes/decodes instances of itself, in order to prevent substitution attacks. I'm wondering whether it would be appropriate to use it in other cases. Specifically if a class conforms to NSCoding by encoding/decoding its instance variables, as opposed to the whole instance of itself, would it still be advisable to implement NSSecureCoding ? EDIT Suppose I have a class that is implementing NSCoding like follows - (void)encodeWithCoder:(NSCoder *)encoder {

archive array of optional structs with NSCoding in Swift?

房东的猫 提交于 2019-12-03 06:55:57
问题 I've done a lot of NSCoding archiving in Obj-C, but I'm not sure how it handles structs in Swift, nor arrays with optional values. Here is my code: public struct SquareCoords { var x: Int, y: Int } and here is the class which I need to store: public class Player: NSCoding { var playerNum: Int var name = "" private var moveHistory: [SquareCoords?] = [] init (playerNum: Int, name: String) { self.playerNum = playerNum self.name = name } public required init(coder aDecoder: NSCoder!) { playerNum

Inspecting files of type “NeXT/Apple typedstream” version 4 (NSArchiver)

拜拜、爱过 提交于 2019-12-03 01:39:17
For a data recovery program I need to be able to extract the values+types from files written by NSArchiver, without having access to Apple's CF / NS frameworks. The OS X file command reports such files as: NeXT/Apple typedstream data, little endian, version 4, system 1000 Is there any documentation on how these files are encoded, or has anyone come up with code that can parse them? Here's an example of such data (also: downloadable ): 04 0B 73 74 72 65 61 6D 74 79 70 65 64 81 E8 03 ..streamtyped... 84 01 40 84 84 84 12 4E 53 41 74 74 72 69 62 75 ..@....NSAttribu 74 65 64 53 74 72 69 6E 67 00

How to use persist & retrieve an NSCoding compliant object to app Document directory in Swift 3?

核能气质少年 提交于 2019-12-01 12:07:35
Here's a NSCoding compliant object. I would like to save and recover it from the app's documents directory in Swift 3. I imagine it's a save method and recover method. How is this done? import Foundation class Book: NSObject, NSCoding { var title: String var author: String var pageCount: Int var categories: [String] var available: Bool init(title:String, author: String, pageCount:Int, categories:[String],available:Bool) { self.title = title self.author = author self.pageCount = pageCount self.categories = categories self.available = available } // MARK: NSCoding required convenience init?