nsarray

How to get values from NSDictionaries inside an NSArray

我的未来我决定 提交于 2019-12-04 00:42:39
I'd like to know if it's possible to get a values from a desired key inside an NSDictionary that is in NSArray . Example: NSArray *array = @[ @{@"title" : @"title 1", @"description" : @"description 1"}, @{@"title" : @"title 2", @"description" : @"description 2"}, @{@"title" : @"title 3", @"description" : @"description 3"} ]; I'd like to get (without creating a new NSMutableArray ) all the titles inside my NSArray . Maybe I'm doing something wrong and my approach is bad altogether. I know I could create a new class and have 2 properties (title, desc), but is there a way without creating a class

How can i convert a NSData to NSArray? [duplicate]

不羁的心 提交于 2019-12-04 00:29:58
Possible Duplicates: How to convert NSArray to NSData? Need to convert NSData to NSArray HI, I have a NSData object named as "myNsData"(it is converted form of NSArray) and a NSarray named as "myNsArray. can any one provide me a code to convert a NSData to NSArray? Simon Lee See this post... Convert NSArray to NSData The last comment deals with the reverse.... NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data] I am not sure but can you try NSArray *myNsArray = [NSKeyedUnarchiver unarchiveObjectWithData:myNsData]; 来源: https://stackoverflow.com/questions/6108924/how-can-i-convert

NSPredicate to filter between two dates of NSString type

佐手、 提交于 2019-12-03 20:34:46
I've some data (as NSDictionary in an NSMutableArray ), a sample data is like, Consider each row as NSDictionary and entire table is an NSMutableArray contains events. I want to result between two dates, so I'm using NSPredicate to filter my data. Here's my code snippet for this, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Date >= %@ AND Date <= %@", startDate,endDate]; NSArray *filter = [arrayEvents filteredArrayUsingPredicate:predicate]; Test filtration : Case 1: NSString *startDate = @"01/07/14"; NSString *endDate = @"31/07/2014"; Output: All events (rows). Case 2: NSString

How can I convert the NSString to a array?

為{幸葍}努か 提交于 2019-12-03 20:10:12
For example, I read a data like this a\tbcd\tttte\tjjjd\tnjnjnjd\tss\tee and I want to make a array like this: { @"a", @"bcd", @"ttte", @"jjjd", @"njnjnjd", @"ss", @"ee" } How can I do so? Thank you. You can use -componentsSeparatedByString: , as in NSArray *ary = [mystring componentsSeparatedByString:@"\t"]; - (NSArray *)componentsSeparatedByString:(NSString *)separator componentsSeparatedByString: Returns an array containing substrings from the receiver that have been divided by a given separator. (NSArray *)componentsSeparatedByString:(NSString *)separator Parameters separator The separator

How might I check if a particular NSString is present in an NSArray?

自作多情 提交于 2019-12-03 18:00:38
问题 How might I check if a particular NSString is presnet in an NSArray? 回答1: You can do it like, NSArray* yourArray = [NSArray arrayWithObjects: @"Str1", @"Str2", @"Str3", nil]; if ( [yourArray containsObject: yourStringToFind] ) { // do found } else { // do not found } 回答2: Iterating or containsObject are order n ways to find. If you want constant time lookup, you can also maintain a hash table like NSSet or NSHashTable but that increases space but saves time. NSArray* strings = [NSArray

Filter array of dictionaries by NSString

坚强是说给别人听的谎言 提交于 2019-12-03 17:27:44
while implementing search functionality I need to filter array of dictionaries. I am using auto complete textfield method for search bar and am storing it into string. I can able to parse the array,But facing with below json [{"CertProfID":"4","Name":"Dodge","Location":"loc4","City":"city4","State":"state4","Zip":"zip5","Website":"http:\/\/cnn.com","Phone":"phone4","Email":"email4"}, {"CertProfID":"5","Name":"cat","Location":"loc5","City":"city5","State":"State5","Zip":"zip5","Website":"web5","Phone":"phone5","Email":"email5"}] Here I need to filter the dictionaries to make it finish I tried

Storing and Retrieving from a Plist [duplicate]

白昼怎懂夜的黑 提交于 2019-12-03 16:35:05
This question already has an answer here : Closed 7 years ago . Possible Duplicate: iOS: store two NSMutableArray in a .plist file I've always refrained from using plists as I'm not really sure how to use one. Could anyone give a simple code example of using a plist? I'm interested in saving an NSArray or NSDictionary to a plist and then retrieving it again later. Are there any advantages/disadvantages to storing either an NSArray or an NSDictionary ? Also, are there any rules with regards to what you can or can't store in a plist? Lolloz89 You can store the following data types in a .plist

Grab all values in NSDictionary inside an NSArray

一世执手 提交于 2019-12-03 16:15:56
I have an NSArray full of NSDictionary objects, and each NSDictionary has a unique ID inside. I want to do lookups of particular dictionaries based on the ID, and get all the information for that dictionary in my own dictionary. myArray contains: [index 0] myDictionary object name = apple, weight = 1 pound, number = 294, [index 1] myDictionary object name = pear, weight = .5 pound, number = 149, [index 3] myDictionary object (etc...) I want to get the name and weight for the second dictionary object (I won't know the index of the object... if there were only two dicts, I could just make a

How to check if an NSString contains one of the NSStrings in an NSArray?

坚强是说给别人听的谎言 提交于 2019-12-03 15:35:34
问题 I'm making an iOS app and I need to figure out if an NSString contains any of the NSStrings in an NSArray . 回答1: BOOL found=NO; for (NSString *s in arrayOfStrings) { if ([stringToSearchWithin rangeOfString:s].location != NSNotFound) { found = YES; break; } } 回答2: It may be a silly optimization for your use case, but depending on how large the array is that you are iterating, it may be helpful/more performant to use NSArray's indexOfObjectWithOptions:passingTest: method. With this method you

Unrecognized Selector Sent to Instance [NSCFString subarrayWithRange:]

十年热恋 提交于 2019-12-03 13:32:46
I have the following code which is producing this error. I cannot understand why the subarrayWithRange message is being sent to a string? When it is clearly an array? static const int kItemsPerView = 20; NSRange rangeForView = NSMakeRange( page * kItemsPerView, kItemsPerView ); NSMutableArray *temp = [[APP_DELEGATE keysArray] mutableCopyWithZone:NULL]; NSArray *itemsForView = [temp subarrayWithRange:rangeForView]; for (int loopCounter = 0;loopCounter < r*c;loopCounter++){ NSLog(@"%i: %@ ", loopCounter, [itemsForView objectAtIndex:loopCounter]); } Error: -[NSCFString subarrayWithRange:]: