How to Read Plist without using NSDictionary in Swift?

The native Swift way is to use PropertyListSerialization if let url = Bundle.main.url(forResource:”Config”, withExtension: “plist”) { do { let data = try Data(contentsOf:url) let swiftDictionary = try PropertyListSerialization.propertyList(from: data, format: nil) as! [String:Any] // do something with the dictionary } catch { print(error) } } You can also use NSDictionary(contentsOf: with a type cast: if … Read more

Why does string show up in NSDictionary with quotes, but others don’t? [duplicate]

The quotes appear because the string contains something besides basic alphanumerics — in this case, an underscore. It’s the same reason “tbyg.jpg” and “6bcb4126-4bbe-4b3d-be45-9a06cf56a22f” have quotes (they contain a dot and dashes, respectively). That’s just how the description method works. It wouldn’t cause your second log to fail.

Searching NSArray of NSDictionary objects

NSArray *contacts = …; //your array of NSDictionary objects NSPredicate *filter = [NSPredicate predicateWithFormat:@”contact_type = 42″]; NSArray *filteredContacts = [contacts filteredArrayUsingPredicate:filter]; After this, filteredContacts will contain only the contacts whose contact_type is 42. If you need to search for more than one kind of contact_type, then simply use an OR in the predicate: filter = … Read more

Convert NSArray to NSDictionary

Try this magic: NSDictionary *dict = [NSDictionary dictionaryWithObjects:records forKeys:[records valueForKey:@”intField”]]; FYI this is possible because of this built-in feature: @interface NSArray(NSKeyValueCoding) /* Return an array containing the results of invoking -valueForKey: on each of the receiver’s elements. The returned array will contain NSNull elements for each instance of -valueForKey: returning nil. */ – (id)valueForKey:(NSString *)key;

Converting NSString to NSDictionary / JSON

I believe you are misinterpreting the JSON format for key values. You should store your string as NSString *jsonString = @”{\”ID\”:{\”Content\”:268,\”type\”:\”text\”},\”ContractTemplateID\”:{\”Content\”:65,\”type\”:\”text\”}}”; NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; Now if you do following NSLog statement NSLog(@”%@”,[json objectForKey:@”ID”]); Result would be another NSDictionary. { Content = 268; type = text; }

Replace occurrences of NSNull in nested NSDictionary

A small modification to the method can make it recursive: @interface NSDictionary (JRAdditions) – (NSDictionary *) dictionaryByReplacingNullsWithStrings; @end @implementation NSDictionary (JRAdditions) – (NSDictionary *) dictionaryByReplacingNullsWithStrings { const NSMutableDictionary *replaced = [NSMutableDictionary dictionaryWithDictionary: self]; const id nul = [NSNull null]; const NSString *blank = @””; for (NSString *key in self) { const id object = [self … Read more