nsdictionary

NSDictionary with NSDates as keys

情到浓时终转凉″ 提交于 2019-12-07 12:10:44
问题 Is it possible to have an NSdictionary where the keys are NSDates and also have it writeable/archiveable to disk? 回答1: Not using property lists, as only string keys are allowed there. You should be able to write it using NSKeyedArchiver , but that has the disadvantage of being a more opaque format. Alternatively, you could of course make a copy of the dictionary where you convert the dates to strings. 回答2: Yes, this should work just fine - and NSDate elements are also suitable for plist

writeToFile not working with NSDictionary [duplicate]

↘锁芯ラ 提交于 2019-12-07 08:46:15
问题 This question already has answers here : Why NSMutableDictionary don't want write to file? (2 answers) Closed 5 years ago . I looked around other similar questions about this but nothing really worked. I managed to write only one pair (object / key) of the dictionary (e.g.: setObject:itemProperties[0] forKey[0]) on my Plist. But I would like all the objets and keys to be added. I didn't managed so far (return the error). Any help? // Path to Documents Folder NSArray *paths =

NSDictionary以及NSMutableDictionary的用法

最后都变了- 提交于 2019-12-07 08:45:00
1、NSDictionary (不可变字典) 字典的初始化 //一个key - value NSDictionary *dic1 = [NSDictionary dictionaryWithObject:@"@123" forKey:@"key1"]; //两个以上 key - value NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"value1",@"key1",@"value2",@"key2" ,nil]; //用字典为另一个子字典初始化 NSDictionary *dic3 = [NSDictionary dictionaryWithDictionary:dic1] //新方法赋值 NSDictionary *dic4 = @{@"key1": @"value1",@"key2": @"value2"}; //以为件内容初始化一个字典 NSDictionary *dic5 = [NSDictionary dictionaryWithContentsOfFile:path]; //将字典的key转成一个枚举对象,用于遍历 NSEnumerator *enumerator = [dic4 keyEnumerator]; 字典的常用方法 //返回字典键值对的个数 NSInteger count

Why do some dictionary keys have quotes and others don't when printing from debugger?

回眸只為那壹抹淺笑 提交于 2019-12-07 08:25:40
问题 So I am currently sending back from my server a JSON object. If I do a print of the responseObject in XCode, I get the following: Printing description of responseObject: { order = 3; "picture_bucket_name" = test; "picture_creation_date" = "2013-01-06T21:49:54.546Z"; "picture_identifier" = 61; "picture_url_with_bucket" = "test/pictures/sop/steps/test_default_320_320.png"; "sub_order" = 0; } Why is the Order key not in " "? This is the only key with a Number that I have to convert from NSString

NSDate as keys for NSDictionary

坚强是说给别人听的谎言 提交于 2019-12-07 07:10:24
问题 Is it possible to add NSDate as keys and some arrays as it values in a NSDictionary? I dont have any requirement of writing the dictionary to disk - archiving or unarchiving, just as this guy needs it: NSDictionary with NSDates as keys But, why I want NSDate to be added as keys specifically is so that I can fetch all keys from the dictionary and do some computations like, fetching the dates from within a range. Whether two objects with same date value share same memory when created? Is it

NSJSONSerialization returns “<null>” string

烂漫一生 提交于 2019-12-07 05:38:37
问题 I'm try to set an NSDictionary to a JSON object retrieved from the server, I'm doing that in this line: _peopleArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; It works fine and properly creates the dictionary. However, I have a problem, values that are null in the JSON object are stored as "<null>" string values in the dictionary. Is there any way to fix this or work around it? I want to avoid traversing through the entire thing and setting them to @"" . Thanks for

Fast Enumeration With an NSMutableArray that holds an NSDictionary

99封情书 提交于 2019-12-07 05:23:52
问题 Is it possible to use fast enumeration with an NSArray that contains an NSDictionary? I'm running through some Objective C tutorials, and the following code kicks the console into GDB mode NSMutableArray *myObjects = [NSMutableArray array]; NSArray *theObjects = [NSArray arrayWithObjects:@"easy as 1",@"easy as two", @"Easy as Three"]; NSArray *theKeys = [NSArray arrayWithObjects:@"A",@"B",@"C"]; NSDictionary *theDict = [NSDictionary dictionaryWithObjects:theObjects forKeys:theKeys];

Xamarin.iOS, convert Dictionary to NSDictionary

让人想犯罪 __ 提交于 2019-12-06 20:57:57
问题 Am trying to integrate Branch.io in my Xamarin project and came across this requirement to convert c#'s Dictionary to NSDictionary. Tried dictionary as NSDictionary //Didn't work Tried this as well private NSMutableDictionary BranchData (Dictionary<string, object> data) { List<string> keys = data.Keys.ToList(); NSMutableDictionary branchData = new NSMutableDictionary (); foreach (string key in keys) { branchData.Add (new NSString(key), data[key] as NSObject); } return branchData; } Didn't

runtime应用场景

ⅰ亾dé卋堺 提交于 2019-12-06 17:57:26
一、runtime简介 RunTime简称运行时。OC就是 运行时机制 ,也就是在运行时候的一些机制,其中最主要的是消息机制。对于C语言, 函数的调用在编译的时候会决定调用哪个函数 。对于OC的函数,属于 动态调用过程 ,在编译的时候并不能决定真正调用哪个函数,只有在真正运行的时候才会根据函数的名称找到对应的函数来调用。事实证明: 在编译阶段,OC可以 调用任何函数 ,即使这个函数并未实现,只要声明过就不会报错。在编译阶段,C语言调用 未实现的函数 就会报错。 二、runtime作用 1.发送消息 方法调用的本质 ,就是让对象发送消息。objc_msgSend,只有对象才能发送消息,因此以objc开头.使用 消息机制 前提,必须导入#import 消息机制简单使用 // 创建person对象 Person *p = [[Person alloc] init]; // 调用对象方法 [p eat]; // 本质:让对象发送消息 objc_msgSend(p, @selector(eat)); // 调用类方法的方式:两种 // 第一种通过类名调用 [Person eat]; // 第二种通过类对象调用 [[Person class] eat]; // 用类名调用类方法,底层会自动把类名转换成类对象调用 // 本质:让类对象发送消息 objc_msgSend([Person class

False order when reading Dictionary from PList

北城余情 提交于 2019-12-06 16:47:34
I have a plist from which i am trying to access its animations in sequence (as defined in the PList) but when I store it in NSDictionary and then try to play animation one by one it is not playing them in sequence. e.g, int index = 0; [self playAnimation:[animTypes objectAtIndex:index++]]; [self playAnimation:[animTypes objectAtIndex:index++]]; This is the code of my Plist: <plist version="1.0"> <dict> <key>Boy</key> <dict> <key>Enter</key> <dict> <key>disabled</key> <false/> <key>halfCycle</key> <true/> <key>fps</key> <integer>1</integer> <key>defaultFrame</key> <integer>0</integer> <key