nsdictionary

writeToFile not working with NSDictionary [duplicate]

瘦欲@ 提交于 2019-12-05 17:44:14
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 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths

When is NSCopying needed?

余生长醉 提交于 2019-12-05 14:57:55
问题 I know it's needed if your object will be used as a key in an NSDictionary. Are there any other times like this that NSCopying is required? If I think I don't need my model objects to conform to NSCopying, am I probably wrong? 回答1: When it's being passed to a copy property or any other method that is documented as copying its argument. 回答2: Think of the NSCopying protocol as the objective-C version of cloning routines. If a caller was to clone your object, what is the behavior you would want?

How to deserialize json object and assign to a NSDictionary in iOS

我的未来我决定 提交于 2019-12-05 12:46:57
问题 This is my code for handling server response. - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"connectionDidFinishLoading : %@", [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding]); } This is the message Server response to me, NSLog JSON displays in console. connectionDidFinishLoading : {"ErrorCode":"CssParameterException","ErrorMessage":"An error has occurred, please try again later.","Success":false} My question is: how do I deserialize the

NSDate as keys for NSDictionary

依然范特西╮ 提交于 2019-12-05 12:37:46
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 possible to have NSDate as key? Also, what other problems I might face with this assumption? Thanks, Raj

NSDictionary's allKeys array messed up - not in the order they are in the dictionary?

烂漫一生 提交于 2019-12-05 11:26:04
in my project I'm pulling data from a .plist, more concretely from an NSDictionary. I init a dictionary with the contents of the .plist, which works well. When I then do NSArray *array = [dict allKeys]; it fills the array with all the keys, but in a totally random order, different to the order they are in the .plist file. I would really need to preserve the order. The keys in the dictionary are arrays, if that could cause a problem. What am I not getting? Thanks a lot in advance! Much like there is no order between items in an NSSet, there's is no inherent order to the key-value pairs within

Fast Enumeration With an NSMutableArray that holds an NSDictionary

蹲街弑〆低调 提交于 2019-12-05 11:02:50
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]; [myObjects addObject:theDict]; for(id item in myObjects) { NSLog(@"Found an Item: %@",item); } If I replace the

NSJSONSerialization returns “<null>” string

旧巷老猫 提交于 2019-12-05 08:51:32
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 any help! ~Carpetfizz There is nothing I guess, though it can be easily corrected from api makers, if

Copying NSDictionary to NSArray

江枫思渺然 提交于 2019-12-05 06:27:09
问题 I have a variable declared as NSDictionary . How can I copy it to an extern const NSArray variable? For example: NSMutableDictionary *selectedItem = [self.dataArray objectAtIndex:indexPath.row]; [selectedItem setObject:[NSNumber numberWithBool:targetCustomCell.checked] forKey:@"checked"]; 回答1: allKeys returns an NSArray containing all the keys. allValues returns an NSArray containing all the values. NSArray *keys = [myDict allKeys]; NSArray *values = [myDict allValues]; 来源: https:/

iOS 零耦合架构代码生成器

大兔子大兔子 提交于 2019-12-05 06:23:01
刚刚学习完SpriteKit的第一章, 项目的需求就压过来了, 诶, 时间都去哪啦, 接着之前的热修复架构, 这次为了更加好的进行代码规范, 我们将之间的架构模式进行模板代码生成, 这里会用到一些简单的python, 没接触过的同学们可以先去了解下, 今天我就将零耦合代码生成工具分享与你. 本文来自简书,原文地址: http://www.jianshu.com/p/47d565bf200e 贴上WWDC大会的图振奋一下, 最近苹果股票也赚了不少, 哈哈, 其实代码生成工具好久之前就想试试学着开发, 一直没有头绪和所谓的契机, 最近在学习算法的时候顺带学了下python, 发现python的写文件的代码之简洁, 再看看OC, 诶... 刚学iOS的时候还觉得OC是最好的语言, 说实话, 现在好久不敲OC, 都有些手生了. 先按之前的架构写出对应OC模板 没看过Swift版的点击 --> Hybird 实现热修复架构 Downgradable 生成器目录结构 ├── Template //模板文件 │ ├── ControllerTemplate .h │ ├── ControllerTemplate .m │ ├── InterfaceTemplate .h │ ├── ModelTemplate .h │ ├── ModelTemplate .m │ ├──

Byte size of an NSDictionary

倾然丶 夕夏残阳落幕 提交于 2019-12-05 01:10:15
This may sound like a completely stupid question, but how can I get the size in bytes of an NSDictionary? Can I convert it to NSData, and then get the length of that? Help! You should say more about why you care about the size of the dictionary in bytes, because the answer might be different depending. In general, the "size" of an NSDictionary's footprint in memory is not something you can see or care about. It abstracts its storage mechanism from the programmer, and uses some form of overhead beyond the actual data it's storing. You can, however, serialize the dictionary to NSData. If the