nsarray

NSArray full of NSDictionaries. How to find index of object?

≯℡__Kan透↙ 提交于 2020-01-01 09:24:12
问题 I have an array which is filled with NSDictionaries . I want to find the index of one of the dictionary, but what I know about this dictionary is only a value for key @"name". How do I do it ? 回答1: Find index of first dictionary in theArray whose value for @"name" is theValue : NSUInteger index = [theArray indexOfObjectPassingTest: ^BOOL(NSDictionary *dict, NSUInteger idx, BOOL *stop) { return [[dict objectForKey:@"name"] isEqual:theValue]; } ]; index will be NSNotFound if no matching object

How to convert NSArray to NSMutableArray

痞子三分冷 提交于 2020-01-01 04:00:07
问题 ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); NSMutableArray *tempPeoples=[[NSMutableArray alloc]init]; for(int i=0;i<nPeople;i++){ ABRecordRef i1=CFArrayGetValueAtIndex(allPeople, i); [tempPeoples addObject:i1]; // [peoples addObject:i1]; }// end of the for loop peoples=[tempPeoples copy]; This code gives exception b/c I want to convert NSMutableArray to

How do I get a list of countries in Swift ios?

余生颓废 提交于 2020-01-01 03:59:05
问题 I've already seen two similar questions to mine, but the answers for those questions do not work for me. I have an old project with a list of countries manually typed out inside a set of square brackets. I can easily use this in my pickerView but I'm wondering if there is a more efficient way to do this? I will be using the list of countries in a UIPickerView. 回答1: You can get a list of countries using the NSLocale class's isoCountryCodes which returns an array of [String] . From there, you

How to add object at first index of NSArray

*爱你&永不变心* 提交于 2019-12-31 09:29:10
问题 I want to add @"ALL ITEMS" object at the first index of NSARRAY. Initially the Array has 10 objects. After adding, the array should contains 11 objects. 回答1: First of all, NSArray need to be populated when it is initializing. So if you want to add some object at an array then you have to use NSMutableArray. Hope the following code will give you some idea and solution. NSArray *array = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"0", nil]; NSMutableArray

Sorting an NSArray by a key-value relationship that is 2 levels deep

偶尔善良 提交于 2019-12-31 05:33:07
问题 I have an NSArray of UILocalNotification objects that I need to sort according to a key within the UILocalNotification's userInfo property, which is an NSDictionary. I know how to sort NSArrays by a value that is one level deep, e.g., a key within an array of NSDictionaries, but two levels deep I'm lost. I want to do something like this is psuedo-code: NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"userInfo.personName" ascending:YES]; //the personName key within

Displaying NSArray of files in a UITableView - iOS 5

陌路散爱 提交于 2019-12-31 04:50:10
问题 I have an app that allows users to save and open text files. Saving and opening files is fairly straightforward and easy, but I have to give the user an easy way to select a file to open. I decided to do this with a UITableView . When the TableView loads in my view controller, my goal is to populate the TableView with the names of all of the user's text files from within the Documents folder (part of the iOS App Sandbox). I have a general idea of how to do this: Get the contents of the

iPad large NSArray - initWithObjects vs. ArrayWithObjects

折月煮酒 提交于 2019-12-30 07:40:17
问题 can anyone clear this up for me ? I am building an iPad App that has a TableViewController that is supposed to show something between 1000 and 2000 strings. I have those NSStrings in a Singleton. In the init Method of the Singleton I initialize an Array that holds all the data ( does not have to be the final way to do it - was just a quick copy and paste for testing ) I did an self.someArray = [[NSArray alloc]initWithObjects: followed by the large number of strings, followed by nil. that

iPad large NSArray - initWithObjects vs. ArrayWithObjects

寵の児 提交于 2019-12-30 07:40:05
问题 can anyone clear this up for me ? I am building an iPad App that has a TableViewController that is supposed to show something between 1000 and 2000 strings. I have those NSStrings in a Singleton. In the init Method of the Singleton I initialize an Array that holds all the data ( does not have to be the final way to do it - was just a quick copy and paste for testing ) I did an self.someArray = [[NSArray alloc]initWithObjects: followed by the large number of strings, followed by nil. that

insertObject: atIndex: - index 3 beyond bounds for empty array

不打扰是莪最后的温柔 提交于 2019-12-30 07:21:09
问题 I create an array based on a dictionaries key's: factsBuiltArray = [NSMutableArray arrayWithCapacity: 6]; if ([statusDict count] == 10) { for (NSString *key in [statusDict allKeys]) { if ([key isEqualToString: @"currenciesAndConversions"]) { [factsBuiltArray insertObject:key atIndex: 0]; } else if ([key isEqualToString: @"languageAndTranslations"]) { [factsBuiltArray insertObject:key atIndex: 1]; } else if ([key isEqualToString: @"plugSize"]) { [factsBuiltArray insertObject:key atIndex: 2]; }

Sort NSArray of NSDictionaries by string date in key?

懵懂的女人 提交于 2019-12-30 06:39:13
问题 I have been struggling to find an easy way to sort an NSMutableArray that contains NSDictionaries. Each NSDictionary has a key named "Date" which contains an NSString of a date (ex: 10/15/2014). What I am looking to do is sort the array based on those strings in ascending order. I have tried this with no luck: NSComparisonResult dateSort(NSString *s1, NSString *s2, void *context) { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MM/dd/yy"]; NSDate *d1 =