nsdictionary

ObjC to Swift conversion of NSDictionary to NSObject : AnyObject

99封情书 提交于 2019-12-04 18:21:30
I'm implementing Segment.com's iOS library with Swift and all is working great, just stuck on the code conversion below of the identify method: ref: https://segment.com/docs/libraries/ios/#identify [[SEGAnalytics sharedAnalytics] identify:@"userId" traits:@{ @"email": @"em@il.com" }]; where traits is an NSDictionary *, optional Xcode tells me (typeahead hints) that in Swift it translates to: SEGAnalytics.sharedAnalytics().identify(userId: String!, traits: [NSObject : AnyObject]!) As a new Swift developer I'm struggling to get the syntax right to send an object into traits. How can I send in my

Swift Dynamic Cast Failed on NSJSONSerialization

北城以北 提交于 2019-12-04 18:17:29
I have a JSON Data which looks like: [ { "Name" : "Ernst Handel", "City" : "Graz", "Country" : "Austria" }, { "Name" : "Wolski Zajazd", "City" : "Warszawa", "Country" : "Poland" } ] and I am converting it to NSDictionary using: var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData( data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary I usually use this. Works for both numeric and associative types of JSON. It works for your as well. I tried. func JSONParseArray(jsonString: String) -> [AnyObject] { if let data = jsonString.dataUsingEncoding

Comparing NSMutableArray Elements for Values

末鹿安然 提交于 2019-12-04 16:47:57
I am looking for a way to compare the contents of two NSMutableArray objects. Both arrays are filled with NSMutableDictionaries which were allocated separately but occasionally contain the same data. Simplified Example: NSMutableArray *firstArray = [[NSMutableArray alloc] init]; NSMutableArray *secondArray = [[NSMutableArray alloc] init]; NSMutableDictionary *a = [[NSDictionary alloc] init]; [a setObject:@"foo" forKey:"name"]; [a setObject:[NSNumber numberWithInt:1] forKey:"number"]; NSMutableDictionary *b = [[NSDictionary alloc] init]; [b setObject:@"bar" forKey:"name"]; [b setObject:

NSDictionaryController doesn't seem to observe changes to content dictionary

拜拜、爱过 提交于 2019-12-04 15:54:09
I must be missing something simple, but I am having some trouble binding a tableView to an NSDictionaryController. Here is a model of my current scheme: TableViewColumn --bindsTo-->DictionaryController.arrangedObjects.(value or key) --bindsTo-->someClass.someClassMember.aDictionary. I've tested the tableView by adding an entry to aDictionary on init, which is displayed correctly. But when another method produces an object that is then added to aDictionary, the TableView doesn't seem to update or even know that aDictionary now has two entries. I've tried everything I can think of. I am not

NSDictionary read data

不问归期 提交于 2019-12-04 14:12:07
I have now tried to get this to work for a few hours but just cannot get it right. I have the following code: NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSArray arrayWithObjects:@"currentGame1", @"currentGameType1", @"currentGameQuestion1", @"currentGameRightAnswers1", @"currentGameType1", @"numberOfType0Games1", @"type0Results1", @"numberOfType1Games1", @"type1Results1",@"numberOfType2Games1", @"type2Results1",nil], @"Player1", [NSArray arrayWithObjects:@"currentGame2", @"currentGameType2", @"currentGameQuestion2", @"currentGameRightAnswers2", @"currentGameType2", @

Split NSArray into sub-arrays based on NSDictionary key values

天涯浪子 提交于 2019-12-04 11:37:47
We have an app that calls a SOAP web service and retrieves a long list of XML, which the app then parses into an NSArray of NSDictionary objects. The NSArray contains a list of Rental Apartment information, each of which is stored into an NSDictionary . The entire list may contain 10 different types of Apartments (i.e. 2-room, 3-room), and we need to split the NSArray into smaller NSArray s based on Room-Type, which has the key "roomType" in the NSDictionary objects. Currently our algorithm is Use [NSArray valueForKeyPath:@"@distinctUnionofObjects.room-type"] to obtain a list of unique room

How to get a value from a JSON Object using NSJSONSerialization

╄→尐↘猪︶ㄣ 提交于 2019-12-04 09:52:24
I can retrieve the JSON object and display it, but how do I get the value from "lat" and "lng" to use in Xcode? My Code: NSString *str=[NSString stringWithFormat:@"https://www.<WEBSITE>]; NSURL *url=[NSURL URLWithString:str]; NSData *data=[NSData dataWithContentsOfURL:url]; NSError *error=nil; NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSLog(@"Your JSON Object: %@ Or Error is: %@", dictionary, error); JSON Object: ( { response = { lat = "52.517681"; lng = "-115.113995"; }; } ) I cant seem to access any of the data. I've tried:

Sorting an NSArray by an NSDictionary value

梦想的初衷 提交于 2019-12-04 09:39:46
问题 I'm trying to sort an array that would look something like this: (please ignore the fact these people are well past any living age! I just needed large numbers) NSDictionary *person1 = [NSDictionary dictionaryWithObjectsAndKeys:@"sam",@"name",@"28.00",@"age",nil]; NSDictionary *person2 = [NSDictionary dictionaryWithObjectsAndKeys:@"cody",@"name",@"100.00",@"age",nil]; NSDictionary *person3 = [NSDictionary dictionaryWithObjectsAndKeys:@"marvin",@"name",@"299.00",@"age",nil]; NSDictionary

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

橙三吉。 提交于 2019-12-04 09:13:05
问题 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 =

NSDictionary Vs. NSArray

你。 提交于 2019-12-04 08:53:56
I am reading on objective-c (a nerd ranch book), and I can't help thinking about this question: How do I decide which collection type, NSArray or NSDictionary (both with or w/o their mutable subclasses), to use when reading content from URL? Let's say am reading JSON data from a PHP script (a scenario am dealing with), which to use? I know it is stated in many references that it depends on structure of data (i.e. JSON), but could a clear outline of the two structures be outlined? Thank you all for helping :) Florian NSArray is basically just an ordered collection of objects, which can be