Skip to main content

Posts

Showing posts with the label nsdata

NSPropertyListSerialization returns nil when trying to convert NSDictionary to NSData

I'm trying to convert an NSDictionary to NSData to store in core data, but I am getting a nil value returned to me. error states 'Unknown format option' after the call. NSString *error = nil; NSData *d = [NSPropertyListSerialization dataFromPropertyList:data format:NSPropertyListImmutable errorDescription:&error]; The data I'm trying to convert is an NSDictionary with NSStrings as keys and values. Here is a dump of the data dictionary: Printing description of data: <CFBasicHash 0xc96fd60 [0x18ecb38]>{type = immutable dict, count = 4, entries => 0 : <CFString 0x17c9fc [0x18ecb38]>{contents = "title"} = <CFString 0xecc8040 [0x18ecb38]>{contents = "test"} 1 : <CFString 0x17ca2c [0x18ecb38]>{contents = "author"} = <CFString 0xc9643f0 [0x18ecb38]>{contents = "test"} 2 : <CFString 0x17ca0c [0x18ecb38]>{contents = "goal"} = <CFString 0xc96f730 [0x18ecb38]>{contents = "te

creating an http body with construction method

I am trying to create a http body that I am going to pass in using NSURLRequest post. I have my connection class all set up. The thing is i have several methods that return NSStrings and UInt32's and one construction method that I want to use to put all of these methods into one http body which will be of data type format. However I'm not sure how to call these methods that return the correct data from my construction method to gather the data into one data object. here is some code that I have (shortened so its a little clearer) these methods are used to return the data needed - (UInt32) addDataVer { UInt32 dataVer = 0; return dataVer; } - (NSString *) addReg { NSString *reg = [[NSString alloc] initWithString:@"abcd1"]; return reg; } - (NSString *) addActiv { NSString *activ = [[NSString alloc] initWithString:@"abcd2"]; return activ; } from here I'm not sure what to do, or how to get the data. I have created a constru

how to encode a UInt32 scalar type into a NSData object

I am currently creating this NSData object. I would like to put in sever different objects that are of type NSString and UInt32. I know how to put a NSString into my NSData object, but I don't know how to do this with a UInt32 scalar type. this is how I do it with a NSString - (void) constructRequest { NSString *mystring = [[NSString alloc] initWithString:[self addMethodName]]; UInt32 protocolInt = [self addProtocolVersion]; NSData* data=[mystring dataUsingEncoding:NSUTF8StringEncoding]; [data writeToFile:@"/Users/imac/Desktop/_dataDump.dat" atomically:YES]; }