nsarray

sorting NSArray of NSStrings by match occurrence

和自甴很熟 提交于 2019-12-11 08:33:34
问题 How can I sort NSArray by search pattern matching? So if for example I have a search pattern equal 'xd' and an array of values: axd bxd xdd gtxd xdc how can I get the output like below: xdc xdd axd bxd gtxd Thank you in advance. 回答1: Use NSArray 's sortedArrayUsingFunction: with a function that orders first by the position of the search term, then by the strings' natural ordering. NSInteger sorter(id arg1, id arg2, void *context) { NSString *searchTerm = (NSString *)context; NSRange range1 =

Filtration by Comparison of Dictionary Objects in NSArray

痴心易碎 提交于 2019-12-11 08:23:52
问题 I have an array of dictionaries that I need to filter in a very specific way. It's easiest to explain by example. Let's say I have an array containing the following three dictionaries where @"threadId", @"subject", @"messageId" are keys: NSDictionary #1: @"threadId" : @"1234" @"subject" : @"hello" @"messageId" : @"0001" NSDictionary #2: @"threadId" : @"1234" @"subject" : @"hello" @"messageId" : @"0002" NSDictionary #3: @"threadId" : @"9101" @"subject" : @"goodbye" @"messageId" : @"0005" I'm

Initialize NSArray with data from NSdictionary

人盡茶涼 提交于 2019-12-11 07:44:32
问题 I receiving data from URL, put it in NSDictionary, and then I need to create NSArray for each tags. My NSDictionary looks like: ( { id = { text = 1; }; logo = { text = "url 1"; }; name = { text = "some name 1"; }; }, { id = { text = 2; }; logo = { text = "url 2"; }; name = { text = "some name 2"; }; }, { id = { text = 3; }; logo = { text = "url 3"; }; name = { text = "some name 3"; }; } ) I want to have array like that: arrLogo = (@"url 1", @"url 2", "url 3"). I'm doing next: arrName=[[dict

What will be the numberOfRowsInSection return type for uitableview when XML data is retrieved?

我是研究僧i 提交于 2019-12-11 07:27:15
问题 I have a NSMutableArray named as records and a NSArray . Now I am retrieving an XML attribute and its value, using TBXML parser and inserting the attribute value in the NSArray . This NSArray is an object of records . What will be the numerberOfRowsInSection when I want to display the value of XML data in tableview cell? This is my data retrieving procedure.... [records addObject:[NSArray arrayWithObjects: [TBXML textForElement:id], [TBXML textForElement:productNumber], [TBXML textForElement

STRUCT Array To UserDefaults

狂风中的少年 提交于 2019-12-11 07:13:56
问题 I have a custom Struct class to hold calories, fats, carbs, and protein. Each Time a user enters the data I put it into a variable var theArray : NSMutableArray = [] struct CFCPstruct { let calories : Int! let fats : Int! let carbs : Int! let protein: Int! init(Calories: Int, Fats: Int, Carbs: Int, Protein: Int) { self.calories = Calories self.fats = Fats self.carbs = Carbs self.protein = Protein } } let addLog = [CFCPstruct(Calories: totalCalories, Fats: totalFats, Carbs: totalCarbs, Protein

how can I convert NSArray into specific String?

不想你离开。 提交于 2019-12-11 06:56:31
问题 I'm using facebook-api to fetch user's friends. The code is as follows: let params = ["fields": "id"] let request = FBSDKGraphRequest(graphPath: "me/friends", parameters: params) request.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in if error != nil { let errorMessage = error.localizedDescription print(errorMessage) /* Handle error */ } else if result.isKindOfClass(NSDictionary){ /* handle response */ let defaults =

NSUserdefaults works on Simulator but not on Device

人盡茶涼 提交于 2019-12-11 06:45:11
问题 I would like to save an NSArray to NSUSerDefaults . If I do it on Simulator everything works, if I do it on Device, it doesnt work. NSArray *Test1 = [Daten copy]; NSArray *Test2 = [Kosten copy]; [prefs setObject:Test1 forKey:@"Daten"]; [prefs setObject:Test2 forKey:@"Kosten"]; I am using the above code. prefs is a normal NSUserDefaults , like NSUserDefaults *prefs = [NSUserDefaults standartUserDefaults]; ... Daten & Kosten are Mutable Arrays, to work with. Everything works on simulator, but

“Unable to restore previously selected frame” when looping through NSDictionary

自作多情 提交于 2019-12-11 06:25:05
问题 I got the following errors in my app: warning:Unable to restore previously selected frame warning:Unable to restore previously selected frame when using the following code: NSDictionary *feed = [json_parser objectWithString:json_str error:nil]; for(NSDictionary *feed_item in [feed objectForKey:@"items"]) { PropertyData *propertyData; // mere data model class with properties only,no methods [propertyData release]; } with this line hightlighted Thread 1: Program received signal: "EXC_BAD_ACCESS

How to store NSArray on Secondary storage?

喜欢而已 提交于 2019-12-11 06:24:49
问题 I am new in iOS, i want to store the values in NSArray onto secondary storage so that i can access it later, The array is large response from web service, i want to parse and show it, It is not efficeint to parse the array and store in sqlite DB, I want alternate way to save that array, may be in text file, so that i cant retrieve data from text file and parse it by my parsing function. can we do that ? please give me suggestions Thanks in advance ! 回答1: to save the array to a text file you

Saving Array To File Objective C

不打扰是莪最后的温柔 提交于 2019-12-11 05:51:56
问题 I've been stuck on this for ever and I finally figured it out and now just out of the blue it stopped working again... NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [NSString stringWithFormat:@"%@/scoreCards.dgs",documentsDirectory]; NSMutableArray *savedArrayOfScorecards = [[NSMutableArray alloc]init]; savedArrayOfScorecards = [NSMutableArray