nsdictionary

NSDictionary to NSArray?

…衆ロ難τιáo~ 提交于 2019-12-17 17:56:23
问题 i have a NSDictionary which looks like: { "Item1" = 2.4; "Item2" = 5.5; "Item3" = 15.6; } To use this NSDictionary Items in a Table View i have to transfer it to a NSArray , am i right? So i try: NSDictionary *dict = [myDict objectForKey:@"items"]; for (id item in dict) { [_myArray addObject:[dict objectForKey:item]]; } But _myArray keeps empty? What am i doing wrong? 回答1: Leaving aside the technical issues with the code you posted, you asked this: To use this Dictionary Items in a Table View

Directly accessing nested dictionary values in Objective-C

匆匆过客 提交于 2019-12-17 15:37:45
问题 Is there a way to directly access an inner-array of an an outer array in Objective-C? For example, a call to an external data source returns the following object: { bio = "this is the profile.bio data"; "first_name" = John; "last_name" = Doe; location = { name = "Any Town, Any State"; }; metadata = { pictures = { picture = "https://picture.mysite.com/picture.jpeg"; } } } I want to be able to access, for example, the location.name or the metadata.pictures.picture data. Dot notation, however,

What is the Java equivalent of Objective-C's NSDictionary?

你。 提交于 2019-12-17 10:59:47
问题 What is the closest implementation of Objective-C's NSDictionary in Java? To me, it looks like HashMap<String, Object> , but I'm very new to Objective-C. Thanks 回答1: NSDictionary is a class cluster (see the "Class Cluster" section in The Cocoa Fundamentals Guide), meaning that the actual implementation is hidden from you, the API user. In fact, the Foundation framework will choose the appropriate implementation at run time based on amount of data etc. In addition, NSDictionary can take any id

Converting NSString to NSDictionary / JSON

折月煮酒 提交于 2019-12-17 10:15:23
问题 I have the following data saved as an NSString : { Key = ID; Value = { Content = 268; Type = Text; }; }, { Key = ContractTemplateId; Value = { Content = 65; Type = Text; }; }, I want to convert this data to an NSDictionary containing the key value pairs. I am trying first to convert the NSString to a JSON objects as follows : NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; However when I try :

Plist Array to NSDictionary

坚强是说给别人听的谎言 提交于 2019-12-17 09:47:21
问题 I have a plist: <plist version="1.0"> <array> <dict> <key>name</key> <string>Alabama</string> <key>abreviation</key> <string>AL</string> <key>date</key> <string>1819</string> <key>population</key> <string>4,627,851</string> <key>capital</key> <string>Montgomery</string> <key>largestCity</key> <string>Birmingham</string> </dict> <dict> <key>name</key> <string>Alaska</string> <key>abreviation</key> <string>AK</string> <key>date</key> <string>1959</string> <key>population</key> <string>683,478<

How to add userInfo to a UIAlertView?

随声附和 提交于 2019-12-17 08:59:39
问题 I would like to know how to add a userInfo object, or any NSDictionary, to a UIAlertView? Thank you. 回答1: If you are on > iOS 4.0 (for blocks) and you only want one or two buttons, you could use this category I made: https://github.com/rsaunders100/UIAlertView-Blocks It bypasses the need to add user info since you put your click handeling function straight into the alert. e.g. #import UIAlertView+Blocks.h ... ... NSString* myUserInfo = @"example"; [UIAlertView displayAlertWithTitle:@"Example

Are keys and values in an NSDictionary ordered?

筅森魡賤 提交于 2019-12-17 06:45:31
问题 I mean: Is the order of keys and values in an NSDictionary always the same like how they were specified when initializing the NSDictionary? Or should I better maintain a seperate NSArray if I really need to know the order of keys? 回答1: No, they are not ordered. As long as you don't add or remove any elements from the dictionary, they will remain in the same order, but as soon as you add or remove an element, the new order will be completely different. If you need the keys/values to be ordered

Swift equivalent to `[NSDictionary initWithObjects: forKeys:]`

假装没事ソ 提交于 2019-12-17 05:11:31
问题 Is there an equivalent for Swift's native Dictionary to [NSDictionary initWithObjects: forKeys:] ? Say I have two arrays with keys and values and want to put them in a dictionary. In Objective-C I'd do it like this: NSArray *keys = @[@"one", @"two", @"three"]; NSArray *values = @[@1, @2, @3]; NSDictionary *dict = [[NSDictionary alloc] initWithObjects: values forKeys: keys]; Of course I can iterate with a counter through both arrays, use a var dict: [String:Int] and add stuff step by step. But

Save NSDictionary to plist

隐身守侯 提交于 2019-12-17 04:58:23
问题 I am using the code found in this post: Mulitple Arrays From Plist, with the same plist formatting. This works successfully, however I do not know how to save the created arrays back into a plist, in the same format. How would I achieve this? EDIT: It is not so much the saving that I need, but the forming of the data to save. The plist is an array of dictionaries with strings and their corresponding keys. All the strings with a certain key are put into an array of their own. How would I put

Can i sort the NSDictionary on basis of key in Objective-C?

主宰稳场 提交于 2019-12-17 04:57:14
问题 Can I sort the NSDictionary on basis of key? 回答1: You can sort the keys and then create an NSMutableArray by iterating over them. NSArray *sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(compare:)]; NSMutableArray *sortedValues = [NSMutableArray array]; for (NSString *key in sortedKeys) [sortedValues addObject: [dict objectForKey: key]]; 回答2: It is much simpler to use objectsForKeys:notFoundMarker: for that NSDictionary *yourDictionary; NSArray *sortedKeys = [yourDictionary