nskeyedarchiver

game state singleton cocos2d, initWithEncoder always returns null

萝らか妹 提交于 2019-12-04 16:03:22
问题 I'm trying to write a basic test "game state" singleton in cocos2d, but for some reason upon loading the app, initWithCoder is never called. Any help would be much appreciated, thanks. Here's my singleton GameState.h: #import "cocos2d.h" @interface GameState : NSObject <NSCoding> { NSInteger level, score; Boolean seenInstructions; } @property (readwrite) NSInteger level; @property (readwrite) NSInteger score; @property (readwrite) Boolean seenInstructions; +(GameState *) sharedState; +(void)

NSKeyedUnarchiver fails to decode a custom object in swift

故事扮演 提交于 2019-12-04 06:02:20
I'm trying a basic implementation of the NSCoding protocol in swift, but it seems I can't success to unarchive an object after it has been correctly archived. Here's my attempt import Cocoa class User: NSObject, NSCoding { var name: String init(name: String) { self.name = name } init(coder aDecoder: NSCoder!) { self.name = aDecoder.decodeObjectForKey("name") as String } func encodeWithCoder(aCoder: NSCoder!) { aCoder.encodeObject(name, forKey: "name") } } let user = User(name: "Gabriele") let encodedUser = NSKeyedArchiver.archivedDataWithRootObject(user) let decodedUser = NSKeyedUnarchiver

NSData from NSKeyedArchiver to NSString

人走茶凉 提交于 2019-12-03 13:50:28
I'm trying to convert NSData generated from NSKeyedArchiver to an NSString so that I can pass it around and eventually convert it back to NSData. I have to pass this as a string (I'm using three20 URL passing). I've gone through various encodings, UTF8, ASCII, etc. and can't get anything to work. NSKeyedArchiver says that the NSData is formated as a property list: NSPropertyListBinaryFormat_v1_0. Does anyone have any idea how I can convert this NSData to a String and back again? Size of the string isn't an issue. Thanks What you want is: id<nscoding> obj; NSData * data = [NSKeyedArchiver

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?

NSKeyedArchiver and NSKeyedUnarchiver with NSMutableArray

回眸只為那壹抹淺笑 提交于 2019-12-03 11:04:26
问题 I'm hoping this isn't something to do with the fact that I'm using a Mutable array here, but this one is baffling me so it wouldn't surprise me if that were the case. BACKGROUND: I have made a small database which is essentially an NSMutableArray containing custom objects, which we can call recordObjects. I set up the array: database = [[NSMutableArray alloc] init]; and my custom object, called "recordObject" contains the following variables and inits: NSString *name; int anInt; Bool aBool; I

game state singleton cocos2d, initWithEncoder always returns null

前提是你 提交于 2019-12-03 10:15:59
I'm trying to write a basic test "game state" singleton in cocos2d, but for some reason upon loading the app, initWithCoder is never called. Any help would be much appreciated, thanks. Here's my singleton GameState.h: #import "cocos2d.h" @interface GameState : NSObject <NSCoding> { NSInteger level, score; Boolean seenInstructions; } @property (readwrite) NSInteger level; @property (readwrite) NSInteger score; @property (readwrite) Boolean seenInstructions; +(GameState *) sharedState; +(void) loadState; +(void) saveState; @end ... and GameState.m: #import "GameState.h" #import "Constants.h"

streaming images over bonjour between two iOS device

為{幸葍}努か 提交于 2019-12-03 09:12:58
My goal is to stream images captured by AVCpatureInput from one iOS device to another via bonjour. Here is my current method: 1) Capture frame from video input - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { /*code to convert sampleBuffer into UIImage */ NSData * imageData = UIImageJPEGRepresentation(image,1.0); [connection sendImage:image]; } 2) Send over TCP connection (from http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone/ ) // Send raw image over network - (void

How to write Dictionary to a file?

我的未来我决定 提交于 2019-12-03 09:07:22
I have a FileHelper class where I've implemented 3 methods whose job is to write a Dictionary contents to a file. Those methods are: func storeDictionary(_ dictionary: Dictionary<String, String>, inFile fileName: String, atDirectory directory: String) -> Bool { let ext = "txt" let filePath = createFile(fileName, withExtension: ext, atDirectory: directory) /**** //If I use this method, file is created and dictionary is saved guard (dictionary as NSDictionary).write(to: filePath!, atomically: true) else { return false } */ guard NSKeyedArchiver.archiveRootObject(dictionary, toFile: (filePath?

NSKeyedArchiver and NSKeyedUnarchiver with NSMutableArray

家住魔仙堡 提交于 2019-12-03 00:35:16
I'm hoping this isn't something to do with the fact that I'm using a Mutable array here, but this one is baffling me so it wouldn't surprise me if that were the case. BACKGROUND: I have made a small database which is essentially an NSMutableArray containing custom objects, which we can call recordObjects. I set up the array: database = [[NSMutableArray alloc] init]; and my custom object, called "recordObject" contains the following variables and inits: NSString *name; int anInt; Bool aBool; I also synthesized methods so I can make calls like: aString = [[database objectAtIndex:someIndex] name]

Unarchiving UIImageView with subviews

倾然丶 夕夏残阳落幕 提交于 2019-12-02 05:12:12
问题 I'm going a bit crazy trying to archive and unarchive a UIImageView which has number of subviews which are custom views derived from UIImageView. Here's what I've done: Add a category to the project to allow for the fact that UIImage does not conform to NSCoding: #import "UIImage-NSCoding.h" #define kEncodingKey @"UIImage" @implementation UIImage(NSCoding) - (id)initWithCoder:(NSCoder *)decoder { if ((self = [super init])) { NSData *data = [decoder decodeObjectForKey:kEncodingKey]; self =