nsdictionary

adding multiple entries to a HashMap at once in one statement

≡放荡痞女 提交于 2019-11-26 18:48:22
问题 I need to initialize a constant HashMap and would like to do it in one line statement. Avoiding sth like this: hashMap.put("One", new Integer(1)); // adding value into HashMap hashMap.put("Two", new Integer(2)); hashMap.put("Three", new Integer(3)); similar to this in objective C: [NSDictionary dictionaryWithObjectsAndKeys: @"w",[NSNumber numberWithInt:1], @"K",[NSNumber numberWithInt:2], @"e",[NSNumber numberWithInt:4], @"z",[NSNumber numberWithInt:5], @"l",[NSNumber numberWithInt:6], nil] I

how to do true deep copy for NSArray and NSDictionary with have nested arrays/dictionary?

青春壹個敷衍的年華 提交于 2019-11-26 18:43:21
Question: Is there a way to use existing objective-c methods to do a full deep copy of a NSDictionary or NSArray, that themselves have nested dictionaries or arrays within them? That is I have read the problem may be when it hits a nested dictionary or array it only copies the pointer to the nested item, and not copy the item truely. Background: So as an example for me I'm trying to load/save the following config with NSUserDefaults and when loading need to convert the immutable copies one gets from NSUserDefault to mutable prior to making changes. Items ( NSDictionary ) Item ( NSDictionary )

Error getting valueForKey in an NSDictionary for key containing @ character

孤街醉人 提交于 2019-11-26 18:33:09
问题 I am trying to get the value of "@type" key in the following NSDictionary named 'robotDesign' robotDesign : { "@id" = "2"; "@type" = "piggyDash"; turnAngle = "-90"; width = "90.0"; } that is a part of a JSON object I got using [NSJSONSerialization JSONObjectWithData: options: error:]; I am using following code to extract @type value NSString * robot_type = (NSString*)[robotDesign valueForKey:@"@type"]; but recive following error: Terminating app due to uncaught exception

How can we store into an NSDictionary? What is the difference between NSDictionary and NSMutableDictionary?

戏子无情 提交于 2019-11-26 18:21:31
I am developing an application in which I want to use an NSDictionary . Can anyone please send me a sample code explaining the procedure how to use an NSDictionary to store Data with a perfect example? Tim The NSDictionary and NSMutableDictionary docs are probably your best bet. They even have some great examples on how to do various things, like... ...create an NSDictionary NSArray *keys = [NSArray arrayWithObjects:@"key1", @"key2", nil]; NSArray *objects = [NSArray arrayWithObjects:@"value1", @"value2", nil]; NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys

Convert JSON feed to NSDictionary

风格不统一 提交于 2019-11-26 17:37:31
Where JSON_CATEGORY_DATA_URL_STRING is my feed URL, which returns fine as: [ { "group":"For Sale", "code":"SSSS" }, { "group":"For Sale", "category":"Wanted", "code":"SWNT" } ] I cannot seem to get a nice NSDictionary (or NSArray ) out of the following code: + (NSDictionary *)downloadJSON { NSDictionary *json_string; NSString *dataURL = [NSString stringWithFormat:@"%@", JSON_CATEGORY_DATA_URL_STRING]; NSLog(@"%@",dataURL); NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:dataURL]]; NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil

Sorting NSArray of dictionaries by value of a key in the dictionaries

这一生的挚爱 提交于 2019-11-26 17:19:22
I have an array populated by dictionaries, and I need to sort the array alphabetically by the values of one of the keys of the dictionaries. This is my array: tu dictus: ( { brand = Ryul; productTitle = Any; quantity = 1; subBrand = "Ryul INJ"; type = Product; }, { brand = Trol; productTitle = Different; quantity = 2; subBrand = ""; type = Brand; }, { brand = Dtor; productTitle = Any; quantity = 1; subBrand = ""; type = Product; }, { brand = Ryul; productTitle = Different; quantity = 2; subBrand = "Ryul CHES"; type = SubBrand; }, { brand = Anan; productTitle = Any; quantity = 1; subBrand = "";

Searching NSArray of NSDictionary objects

走远了吗. 提交于 2019-11-26 16:35:18
问题 I've contacts array where each contact is a dictionary. Each contact has a key "contact_type" which is an NSNumber. Contact type basically represents whether its a Facebook, LinkedIn or Mail contact etc. I've a search array which holds only NSNumber of contact_type's. What I want is to make a temporary array of contacts which I want to search using my search array. I am facing trouble using NSPredicate to create searched contacts array. Can some one guide me on how to do it? 回答1: NSArray

insert NSDictionary into CoreData

旧街凉风 提交于 2019-11-26 16:35:17
问题 I have an NSDictionary and a CoreData Database. I want to insert the NSDictionary into the database. How can I do this (code snippets if possible)? What is the suitable type for the attribute of the dictionary ? 回答1: You would need to serialize your NSDictionary to an NSData, CoreData can hold to NSData. But you won't be able to search (predicate) element of your NSDictionary. And if we think about this, NSDictionary is a collection of data. A Table in a database is kind of a collection of

Convert NSArray to NSDictionary

自古美人都是妖i 提交于 2019-11-26 15:59:40
问题 How can I convert an NSArray to an NSDictionary , using an int field of the array's objects as key for the NSDictionary ? 回答1: - (NSDictionary *) indexKeyedDictionaryFromArray:(NSArray *)array { id objectInstance; NSUInteger indexKey = 0U; NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init]; for (objectInstance in array) [mutableDictionary setObject:objectInstance forKey:[NSNumber numberWithUnsignedInt:indexKey++]]; return (NSDictionary *)[mutableDictionary autorelease

converting NSDictionary object to NSData object and vice-versa

谁说我不能喝 提交于 2019-11-26 15:39:07
问题 I have to convert an NSDictionary object into NSData and further I have to get the same NSDictionary out of the NSData object. How should I go about it? 回答1: use NSKeyedArchiver To convert NSDictionary To NSData NSMutableData *data = [[NSMutableData alloc]init]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data]; [archiver encodeObject:YOURDICTIONARY forKey: YOURDATAKEY]; archiver finishEncoding]; [data writeToFile:YOURFILEPATH atomically:YES]; [data