nscoding

NSCoding protocol question

二次信任 提交于 2019-12-10 15:37:34
问题 I want to add the archiving (NSCoding) protocol to my model class, and then i implement both methods encodeWithCoder:(NSCoder*)coder and initWithCoder:(NSCoder*)coder . MyModelClass has 2 instance variables (NSString and NSImage), so i use the encodeObject:(id)object forKey:(NSString*)string method to encode the object plus the value for particular key. But i keep got the error : *** -encodeObject:forKey: only defined for abstract class. Define -[NSArchiver encodeObject:forKey:]! here's my

How to unit test NSCoding?

元气小坏坏 提交于 2019-12-10 13:23:44
问题 I have an iOS application with data persisted using NSCoding and more precisely NSKeyedArchiver. This application is already available on the App Store. I'm working on version 2 of the application and the data model should change. So I need to handle data model migration. I want it covered by unit tests. In my tests, I want to dynamically generate persisted data with old data model, launch migration and see if everything went well. Currently, archiving an object looks like this :

how to retain my uitextfield values in viewController when i calling?

我的梦境 提交于 2019-12-10 11:54:18
问题 I have a main page having 3 textfield in my first view as i navigate to different view and return back to my first view (i.e after i enter all the values i moving to next page).I want my 3 textfield to retain its value when i go back to my main page here my sample code : NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *mobile = MobileNum.text; [defaults setObject:mobile forKey:self.MobileNum.text]; NSString *amountText = amount.text; [defaults setObject:amountText

When to use NSSecureCoding

眉间皱痕 提交于 2019-12-09 07:41:24
问题 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

iOS Object Archiving from start to finish [closed]

£可爱£侵袭症+ 提交于 2019-12-08 10:00:35
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am working on an iOS App that involves saving and retrieving an NSMutableArray containing multiple instances of a single custom object I made. I have seen several guides such as Apple's Documentation I get the gist of how to do it (I think), it seems I have to use archiving since my objects in the array are

Encode and Decode CGMutablePathRef with ARC

淺唱寂寞╮ 提交于 2019-12-08 09:46:08
问题 Under ARC, is it possible to encode/decode a CGMutablePathRef (or its non-mutable form) using NSCoding ? Naively I try: path = CGPathCreateMutable(); ... [aCoder encodeObject:path] but I get a friendly error from the compiler: Automatic Reference Counting Issue: Implicit conversion of an Objective-C pointer to 'CGMutablePathRef' (aka 'struct CGPath *') is disallowed with ARC What can I do to encode this? 回答1: NSCoding is a protocol. Its methods can only be used with objects that conform to

NSCoding : How to create required init in inherited classes

余生长醉 提交于 2019-12-08 08:26:34
问题 I have the same question as vince (NSCoding required initializer in inherited classes in Swift) I've a class 'Source' and a subclass 'RSSSource'. Theses classes conforms to NSObject and NSCoding which I want to be able to persist with NSKeyedArchiver . I don't know how to create the required convenience init?(coder aDecoder: NSCoder) in the subclass. I would like to call the convenience init of the superclass. PS: I know that I should post a comment on his thread but I can't. (reputation too

iOS Object Archiving from start to finish [closed]

こ雲淡風輕ζ 提交于 2019-12-08 06:58:28
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am working on an iOS App that involves saving and retrieving an NSMutableArray containing multiple instances of a single custom object I made. I have seen several guides such as Apple's Documentation I get the gist of how to do it (I think), it seems I have to use archiving since my objects in the array are not primitive variables, therefore I have already made my objects NSCoding compliant. However I have

override classes variable, or at least variable type in objective-c / cocoa

社会主义新天地 提交于 2019-12-08 04:30:37
问题 My dilemma is as follows: I have a custom subclass of UIImage (I've added some serialization methods i.e. initWithCoder, encodeWithCoder), and I would like to apply my custom subclass as a variable to a UIImageView, or at least a subclass of UIImageView. As you are aware, UIImageView has a variable called "image", that is of type UIImage. I'd like to override this variable with my subclass. My goal is to have a UIimageView that will respond to archivedDataWithRootObject without crashing with

Using NSCoding on a subclass of custom class

≡放荡痞女 提交于 2019-12-07 02:00:59
问题 I am using NSCoding to archive/unarchive a custom class as a method of data persistence. It works fine if the object is a subclass of NSObject, but I also have objects that are subclasses of custom objects. Do I need to change the initWithCoder: method as well as encodeWithCoder? Right now, the properties that are specific to the subclass encode/decode fine, but properties the subclass inherit from the superclass do not. Any thoughts? Here is the basic structure: @interface NewsItem :