nscoding

How do I save/load data in my application using NSCoding?

廉价感情. 提交于 2019-12-12 00:47:47
问题 Yes, I've looked through the numerous questions similar to this that were asked already; however, I still did not quite understand what was going on or at least I couldn't figure out how to do it in my application. So basically my "practice" app has a main view controller that displays two text labels. These text labels are populated by an NSObject class that holds a large array. The user inputs the number in the array they want to go to, and the string at that index in the array becomes the

Why does initWithCoder not return instancetype?

删除回忆录丶 提交于 2019-12-12 00:32:35
问题 It seems that most init methods in Objective-C now tend to return instancetype instead of id . See [UIView initWithFrame:], [UIViewController initWithNibName:bundle:], [NSArray init] and siblings, etc. But initWithCoder uses id . Why is this? Has it just not been updated yet? Or is there a reason it has to be id ? 回答1: It is not updated yet. You can still code it with instance type. - (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { //... }

Swift Decode Array Custom Class Memory Leak

大憨熊 提交于 2019-12-11 13:06:49
问题 I'm saving my app config using NSCoding and am getting a leak in Instruments when using DecodeWithKey. Settings has a property stsSettings stsSettings = (aDecoder.decodeObjectForKey("stsSettings") as! StsSettings) stsSettings has a property array of StsVariables stsVariables = (aDecoder.decodeObjectForKey("stsVariables") as! [StsVariable]) Leaked Object # Address Size Responsible Library Responsible Frame StsVariable 1 0x7fe182d494f0 192 Bytes Foundation _decodeObjectBinary Settings also has

custom object with CCSprite that conforms to NSCoding not displaying

喜欢而已 提交于 2019-12-11 08:01:56
问题 In my effort to save a ScrollingBackground object I've subclassed the CCSprites to conform to NSCoding. The ScrollingBackground doesn't display. Please see the relevant code below. I'm not really sure whats wrong. Please help. ScrollingBackground.h: (CCBackgroundSprite's interface) @interface CCBackgroundSprite: NSObject <NSCoding> @property (nonatomic, assign) float xValue; @property (nonatomic, assign) float yValue; @property (nonatomic, retain) NSString* backgroundStringName; @end

Objective C: I'm trying to save an NSDictionary that contains primitives and object, but error occurred once i tried adding the custom object

假装没事ソ 提交于 2019-12-11 05:49:45
问题 So I have this custom object i made called 'Box', it's throwing the error for that one. Inside of my NSDictionary is... box = [[Box alloc] initWithHeight:20 height:40]; wrap.dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:numberInt, kInt, numberShort, kShort, numberLong, kLong, numberFloat, kFloat, numberDouble, kDouble, numberBool, kBool, nsString, kString, nsDate, kDate, box, @"keybox", nil]; Notice the box object that I created up top and added in the NSDictionary at the very end.

Swift: Error in NSKeyedArchiver

穿精又带淫゛_ 提交于 2019-12-11 05:48:01
问题 Swift 3 iOS 10, Trying to save array with custom objects in NSKeyedArchiver, basically trying to save the table view after the user uses the buttons to switch between sections. I've tried several post to solve the issue but no luck, now I'm trying to do it myself NSCoding and NSKeyedArchiver. Error: Cannot convert value of type '[Blog]' to expected argument type 'NSCoder' Error is in code in Blog.swift, Code that handles NSCoding and my Blog Objects import UIKit class BlogsCoding: NSObject,

How can I encode (with NSCoding) an enum that has no rawValue?

六眼飞鱼酱① 提交于 2019-12-11 04:37:26
问题 I'm trying to make my class conform to NSCoding , but running into problems because one of its properties is an enum, like this: enum Direction { case north case south } If enums were codable I could do it like this: class MyClass: NSObject, NSCoding { var direction: Direction! required init(coder aDecoder: NSCoder) { direction = aDecoder.decodeObject(forKey: "direction") as! Direction } func encode(with aCoder: NSCoder) { aCoder.encode(direction, forKey: "direction") } } but enums aren't

Trouble decoding with NSKeyedUnarchiver

℡╲_俬逩灬. 提交于 2019-12-11 03:42:37
问题 I am writing an app targeted at iOS 4.0 on XCode 3.2.3 where I store some data when the app closes using NSCoder protocol. Saving seems to work fine, the problem is retrieving the data from the saved files. My save method looks like this: -(void)saveMusicalWorksToMemory{ // create the save paths NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *mwPath = [documentsDirectory

How to serialize C array with NSCoding?

我只是一个虾纸丫 提交于 2019-12-11 01:45:45
问题 I have Objective-C class that has C array property. And I want to serialize the property with NSCoding. @interface TestClass : NSObject <NSCoding> @property (nonatomic) int* intArray; @end @implementation TestClass -(instancetype)init { self = [super init]; if (self) { _intArray = (int *)malloc(sizeof(int) * 5); for (int i = 0; i < 5; i++) { _intArray[i] = 0; } } return self; } -(void)dealloc { free(_intArray); } -(instancetype)initWithCoder:(NSCoder *)coder { self = [super init]; if (self) {

Serializing/Storing a UIView and its subviews

南楼画角 提交于 2019-12-10 19:25:15
问题 I'm a relatively new iOS developer, with most of my previous experience coming from .NET. My application is a canvas like system in that there is a parent UIView that contains all the objects the user is placing/resizing/etc as subviews. I want to be able to save these positions/configurations to named files. In .NET, I would have simply subclassed UIView, given it a "title" property, then serialized this to file, and then deserialized them to load them back, but in Cocoa I'm quite lost.