nsdictionary

Remove objects using NSPredicate

社会主义新天地 提交于 2019-11-30 16:29:14
I have the folloving dictionary which has many sub dictionaries. How can I remove objects where isChanged = 1 from parent dictionary using NSPredicate ? { "0_496447097042228" = { cellHeight = 437; isChanged = 1; }; "100000019882803_193629104095337" = { cellHeight = 145; isChanged = 0; }; "100002140902243_561833243831980" = { cellHeight = 114; isChanged = 1; }; "100004324964792_129813607172804" = { cellHeight = 112; isChanged = 0; }; "100004324964792_129818217172343" = { cellHeight = 127; isChanged = 0; }; "100004324964792_129835247170640" = { cellHeight = 127; isChanged = 1; }; } As a simple

Retrieve data from plist

拈花ヽ惹草 提交于 2019-11-30 15:30:02
问题 I have a plist and inside that an array and then set of dictionary elements? How can I retrieve data from the plist to my array? How can I get category names in one array? 回答1: Objective-C // Read plist from bundle and get Root Dictionary out of it NSDictionary *dictRoot = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]]; // Your dictionary contains an array of dictionary // Now pull an Array out of it. NSArray *arrayList = [NSArray

iOS 与 js交互的其一方法 WebViewJavascriptBridge的使用

笑着哭i 提交于 2019-11-30 15:08:48
#import <WebViewJavascriptBridge.h> /// @interface ZWBridgeViewController ()<WKNavigationDelegate, WKUIDelegate, UIGestureRecognizerDelegate> @property ( nonatomic , strong ) ZWCommonNavBar *navBar; @property ( nonatomic , strong ) WKWebView *webView; @property ( nonatomic , strong ) WebViewJavascriptBridge *bridge; @property ( nonatomic , copy ) NSString *urlStr; @property ( nonatomic , copy ) NSString *webTitle; @end @implementation ZWBridgeViewController - ( instancetype )initWithParams:(NSDictionary *)params { self = [ super init]; if ( self ) { } return self ; } - ( void )viewDidAppear:(

Retrieve NSDictionary from NSArray where dictionary key has value X

左心房为你撑大大i 提交于 2019-11-30 12:57:13
I have an NSArray with NSDictionaries . One of the dictionaries keys in one of the arrays contains a value. I want to retrieve the NSDictionary with that value. My array: Array: ( { DisplayName = "level"; InternalName = "Number 2"; NumberValue = 1; }, { DisplayName = "PurchaseAmount"; InternalName = "Number 1"; NumberValue = 3500; } ) So, I would like to get the dictionary which contains DisplayName set to PurchaseAmount (case insensitive). How can I accomplish that? LIKE[cd] will also do it NSArray *filtered = [data filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(DisplayName

Saving enum values into a dictionary

怎甘沉沦 提交于 2019-11-30 11:57:23
问题 How does one save an enum value to a dictionary? When I try the following enum someEnum { field0 = 0, field1 = 1, field2 = 2, }; enum someEnum someEnumObject; and I try to save it to a dictionary using [NSDictionary dictionaryWithObjectsAndKeys:] someEnumObject, @"enum", I get this warning: Semantic Issue: Incompatible integer to pointer conversion sending 'enum behaviour' to parameter of type 'id' 回答1: Use the following to save it to dictionary, [NSNumber numberWithInt:enumValue], @"enum",

With fast enumeration and an NSDictionary, iterating in the order of the keys is not guaranteed – how can I make it so it IS in order?

佐手、 提交于 2019-11-30 11:42:29
I'm communicating with an API that sends back an NSDictionary as a response with data my app needs (the data is basically a feed). This data is sorted by newest to oldest, with the newest items at the front of the NSDictionary. When I fast enumerate through them with for (NSString *key in articles) { ... } the order is seemingly random, and thus the order I operate on them isn't in order from newest to oldest, like I want it to be, but completely random instead. I've read up, and when using fast enumeration with NSDictionary it is not guaranteed to iterate in order through the array. However,

Store selector as value in an NSDictionary

拟墨画扇 提交于 2019-11-30 11:07:54
问题 Is there a way to store a selector in an NSDictionary , without storing it as an NSString ? 回答1: SEL is just a pointer, which you could store in an NSValue : NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSValue valueWithPointer:@selector(foo)], @"foo", nil]; To get the selector back, you can use: SEL aSel = [[dict objectForKey:@"foo"] pointerValue]; 回答2: An alternative to Georg's solution would be to convert the selector into an NSString before storing it the NSDictionary

NSManagedObject as NSDictionary key?

和自甴很熟 提交于 2019-11-30 11:07:53
In my app, I have a NSDictionary whose keys should be instances of a subclass of NSManagedObject . The problem, however, is that NSManagedObject does not implement the NSCopying protocol which means that no Core Data objects / instances of NSManagedObject can be used as dictionary keys even though the -[hash] method works fine for them. Was should I do? There are four options: Use a different object as the dictionary key instead, and lookup from that. [object objectID] or +[NSValue valueWithNonretainedObject:] seem the most obvious Use CFDictionaryCreateMutable() to create a dictionary with

Get all keys of an NSDictionary as an NSArray

て烟熏妆下的殇ゞ 提交于 2019-11-30 10:36:44
问题 Is it possible to get all the keys from a specific NSDictionary as a seperate NSArray ? 回答1: Just use NSArray*keys=[dict allKeys]; In general, if you wonder if a specific class has a specific method, look up Apple's own documentation . In this case, see NSDictionary class reference. Go through all the methods. You'll discover many useful methods that way. 回答2: Yes it's possible. Use allKeys method: NSDictionary *yourDictionary; NSArray * yourKeys yourKeys = [yourDictionary allKeys]; 回答3: And

How to restructure object of NSDictionaries

大憨熊 提交于 2019-11-30 10:08:58
问题 In my debugger this is how my log statement is printing my messages object: self.messages = ( "<lean: 0x7fcf98665140, objectId: vglE1UJ5KI, localId: (null)> {\n messageBody = Jj;\n recipientId = XvvxETqjph;\n senderId = XvvxETqjph;\n timestamp = \"1424991590106.210938\";\n}", "<lean: 0x7fcf98667940, objectId: rgBFYBMKlU, localId: (null)> {\n messageBody = \"test 3 from ian\";\n recipientId = XvvxETqjph;\n senderId = Hoy7UjLzOh;\n timestamp = \"1424631667110.638184\";\n}", "<lean: