开发者

NSDictionary into a NSInputStream

开发者 https://www.devze.com 2023-01-16 06:01 出处:网络
Is it possible to put in my NSDictionary into a NSInputStream? This would be my NSDictionary NSArray *keys = [NSArray arrayWithObjects:@\"name\", @\"device_token\", @\"identifier\", nil];

Is it possible to put in my NSDictionary into a NSInputStream? This would be my NSDictionary

NSArray *keys = [NSArray arrayWithObjects:@"name", @"device_token", @"identifier", nil];
NSArray *values = [NSArray arrayWithObjects:@"Test iPhone", initDeviceToken, [UIDevice currentDevice].uniqueIdentifier, nil];
NSDictionary *parameters = [NSDictionary dictionaryWithObjects:values forKeys:keys];

I tried something like this but it didn开发者_开发知识库't worked...

NSInputStream *inputStream = [[NSInputStream alloc] init];
[inputStream setValue:@"123" forKey:@"identifier"];

Thx a lot


Sure. The way you can do it is serialize your dictionary into an NSData object using NSPropertyListSerialization, and then write your data object out to your NSInputStream.

The downside is that this requires that your dictionary only hold plist objects (numbers, strings, dates, data, arrays, and dictionaries).


Yes.

Any object that conforms to the NSCoding protocol is serializable and as such writable to a stream. Of course the items in a container object must also conform to the NSCoding protocol.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号