nsdictionary

static NSDictionary* const letterValues = @{ … } in a method does not compile

时光总嘲笑我的痴心妄想 提交于 2019-12-03 03:12:25
In a word game for iPhone : I'm trying to use the following code in my custom view Tile.m : - (void)awakeFromNib { [super awakeFromNib]; static NSDictionary* const letterValues = @{ @"A": @1, @"B": @4, @"C": @4, // ... @"X": @8, @"Y": @3, @"Z": @10, }; NSString* randomLetter = [kLetters substringWithRange:[kLetters rangeOfComposedCharacterSequenceAtIndex:arc4random_uniform(kLetters.length)]]; int letterValue = [letterValues[randomLetter] integerValue]; _smallLetter.text = _bigLetter.text = randomLetter; _smallValue.text = _bigValue.text = [NSString stringWithFormat:@"%d", letterValue]; }

How to convert NSDictionary to custom object

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a json object: @interface Order : NSObject @property (nonatomic, retain) NSString *OrderId; @property (nonatomic, retain) NSString *Title; @property (nonatomic, retain) NSString *Weight; - (NSMutableDictionary *)toNSDictionary; ... - (NSMutableDictionary *)toNSDictionary { NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setValue:self.OrderId forKey:@"OrderId"]; [dictionary setValue:self.Title forKey:@"Title"]; [dictionary setValue:self.Weight forKey:@"Weight"]; return dictionary; } In string this is:

How to get data that's inside NSCFDictionary returned by SLRequest on OSX?

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I make this facebook request: SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://graph.facebook.com/fql"] parameters:[NSDictionary dictionaryWithObject:@"SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())" forKey:@"q"]]; [facebookRequest setAccount:_facebookAccount]; [facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) { if(!error){ id

Beautify NSLog of NSArray & NSDictionary

≡放荡痞女 提交于 2019-12-03 03:01:49
问题 I'm dealing with deeply nested NSArray's and NSDictionary's and it's very time consuming to say the least. [data objectatindex:0] valueForKey:@"blah"] etc etc Does anyone know of a nice iOS category to recursively log the structure, highlight the type and show the values? Might be asking a bit much but you never know :) 回答1: Maybe like this? for (id key in dictionary) { NSLog(@"key: %@, value: %@ \n", key, [dictionary objectForKey:key]); } but i can't think of any nice way of getting the

Why doesn’t [NSDictionary allKeys] return a set?

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a reason for NSDictionary to return its keys as NSArray instead of NSSet ? The documentation already states that the order of the keys in the array is undefined, it would sound logical to use a set. 回答1: Sets tend to be somewhat neglected in API design. They'll be included most of the time, but usually long after all the other standard data structures. Add on top of that the fact that besides the very recent NSFastEnumeration, there is no general collection or sequence protocol in Objective-C ― every collection class is completely

Create a dictionary property list programmatically

烈酒焚心 提交于 2019-12-03 02:55:37
I want to programatically create a dictionary which feeds data to my UITableView but I'm having a hard time with it. I want to create a dictionary that resembles this property list (image) give or take a couple of items. I've looked at "Property List Programming Guide: Creating Property Lists Programmatically" and I came up with a small sample of my own: //keys NSArray *Childs = [NSArray arrayWithObjects:@"testerbet", nil]; NSArray *Children = [NSArray arrayWithObjects:@"Children", nil]; NSArray *Keys = [NSArray arrayWithObjects:@"Rows", nil]; NSArray *Title = [NSArray arrayWithObjects:@"Title

Hash value of NSDictionary

假装没事ソ 提交于 2019-12-03 02:53:52
I ran into an issue, where I got the same hash value for different dictionaries. Maybe I'm doing something obvious wrong, but I thought, objects with different content (a.k.a. not equal objects) should have different hash values. NSDictionary *dictA = @{ @"foo" : @YES }; NSDictionary *dictB = @{ @"foo" : @NO }; BOOL equal = [dictA hash] == [dictB hash]; NSAssert(!equal, @"Assuming, that different dictionaries have different hash values."); Any thoughts? There is no guarantee that two different objects will have different hash values. In the latest open-source version of CoreFoundation , the

Using App Links Hosting API for link shared on Facebook from iOS app

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've honestly spent hours on this trying to get it to work. Unfortunately Facebook & App Link's documentation is not clear enough. Even the App Links video from F8 . App Requirements: Share a link to FB as an Open Graph story which users can click on to take them directly into my app and do specific tasks (my app needs to receive specific parameters from the link) Share the link to FB without FB login (i.e. via the Share Dialog and switch to the native iOS FB app as opposed to using API calls). Progress so far: I'm using the following code

Instantiating Custom Class from NSDictionary

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a feeling that this is stupid question, but I'll ask anyway... I have a collection of NSDictionary objects whose key/value pairs correspond to a custom class I've created, call it MyClass . Is there an easy or "best practice" method for me to basically do something like MyClass * instance = [ map NSDictionary properties to MyClass ]; ? I have a feeling I need to do something with NSCoding or NSKeyedUnarchiver , but rather than stumble through it on my own, I figure someone out there might be able to point me in the right direction.

Cannot parsing Json to NSDictionary

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a WebService, which give me the fallowing Json-String back: "{\"password\" : \"1234\", \"user\" : \"andreas\"}" I call the webservice and try to parse the returned data like: [NSURLConnection sendAsynchronousRequest: request queue: queue completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) { if (error || !data) { // Handle the error } else { // Handle the success NSError *errorJson = nil; NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: