nsdata

Null passed to a callee that requires a non-null argument

时光总嘲笑我的痴心妄想 提交于 2019-12-02 00:30:57
问题 I have been using this to convert a CIImage to NSData for ages: NSData *data = [imageRep representationUsingType: NSPNGFileType properties:nil]; Now on El Capitan I have this error on the second line: Null passed to a callee that requires a non-null argument I can solve that by using an empty array on the properties, like this: NSData *data = [imageRep representationUsingType: NSPNGFileType properties: @{}]; but I am suspecting that this can cause me problems in the future. Is this the

Data corrupt after converting byte[] to NSData

淺唱寂寞╮ 提交于 2019-12-02 00:26:40
I have .Net web service response containing a byte[] entry, among other fields. The data is a PDF file. I extract the Dictionary from the received data with: [NSJSONSerialization JSONObjectWithData] Hereafter I use the following code to convert the byte[] to NSData. I then save the result to disk (see last line). When opening the resulting PDF file, I get the following error: "failed to find PDF header: `%PDF' not found." NSArray *byteArray = [rootDictionary objectForKey:@"file"]; unsigned c = byteArray.count; uint8_t *bytes = malloc(sizeof(*bytes) * c); unsigned i; for (i = 0; i < c; i++) {

Save MKPolyline as NSData in NSUserDefaults

こ雲淡風輕ζ 提交于 2019-12-02 00:25:25
问题 My iOS application needs to store an MKPolyline inside of an NSUserDefault . I've been doing a lot of research, and I now know that: NSUserDefaults are a subclass of NSCoder MKPolyline is not a subclass of NSCoder As a result, it is rather difficult to save a polyline to nsuserdefaults. I have attempted to convert the MKPolyline into NSData: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:routeLine]; // routeLine is

Save MKPolyline as NSData in NSUserDefaults

坚强是说给别人听的谎言 提交于 2019-12-02 00:05:53
My iOS application needs to store an MKPolyline inside of an NSUserDefault . I've been doing a lot of research, and I now know that: NSUserDefaults are a subclass of NSCoder MKPolyline is not a subclass of NSCoder As a result, it is rather difficult to save a polyline to nsuserdefaults . I have attempted to convert the MKPolyline into NSData: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:routeLine]; // routeLine is an MKPolyline [defaults dataForKey:@"key"]; [defaults synchronize]; When I try to convert the polyline

Unarchiving UIImageView with subviews

为君一笑 提交于 2019-12-01 23:26:15
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 = [self initWithData:data]; } return self; } - (void)encodeWithCoder:(NSCoder *)encoder { NSData *data =

Creating and using a dummy NSData subclass doesn't work

一个人想着一个人 提交于 2019-12-01 21:49:44
问题 I have a problem with creating my own subclass of NSData , which I want to have a custom description method. Even creating a dummy NSData subclass: @interface MyData : NSData {} @end and @implementation MyData @end and using it results in weird bugs (the function that uses it never exits, and control somehow returns to the run loop). I thought that maybe I am responsible for rewriting the designated initializers of NSData (calling the super implementation), but none is mentioned in the doc.

Creating and using a dummy NSData subclass doesn't work

孤人 提交于 2019-12-01 21:08:10
I have a problem with creating my own subclass of NSData , which I want to have a custom description method. Even creating a dummy NSData subclass: @interface MyData : NSData {} @end and @implementation MyData @end and using it results in weird bugs (the function that uses it never exits, and control somehow returns to the run loop). I thought that maybe I am responsible for rewriting the designated initializers of NSData (calling the super implementation), but none is mentioned in the doc. So: what are the designated initializers of NSData ? what is the bare minimum I need to write for a

Objective-C Convert NSData to NSString

眉间皱痕 提交于 2019-12-01 17:52:36
问题 Here are the code I tried to convert NSData to NSString but the program return "Program received signal:SIGABRT". NSString *string= [NSString stringWithUTF8String:[data bytes]]; OR NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; Is there any other better way to do it? 回答1: Here's a highly up-voted answer that shows how to do it. In a nutshell: NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; The first idea looks like

Objective-C Convert NSData to NSString

[亡魂溺海] 提交于 2019-12-01 17:41:48
Here are the code I tried to convert NSData to NSString but the program return "Program received signal:SIGABRT". NSString *string= [NSString stringWithUTF8String:[data bytes]]; OR NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; Is there any other better way to do it? danh Here's a highly up-voted answer that shows how to do it. In a nutshell: NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; The first idea looks like a fail because of sending [data bytes] . stringWithUTF8String isn't prepared for a void *. The second

NSURLErrorDomain with code=-1100

ぐ巨炮叔叔 提交于 2019-12-01 17:22:59
I was trying to download a picture to my app from The request failed with the error NSURLErrorDomain and the code is really -1100. The url should be correct since I checked it in the browser. Anyone knows why? let userImageURL: String! = "http://i.imgur.com/QhCzQoR.jpg"; let url = NSURL(fileURLWithPath: userImageURL); let request:NSURLRequest = NSURLRequest(URL: url!) NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: { (response:NSURLResponse!, imageData:NSData!, error:NSError!) -> Void in let image = UIImage(data: imageData!); }) The