nsmutablearray

how and where do I initialize an global NSMutableArray in Xcode 5

倖福魔咒の 提交于 2019-11-29 11:01:50
I am trying to initialize a global NSMutableArray that I can add integers to later. I just need to know how and where I should initialize my array so that it can be accessed and changed by any function that I use later in my program. Also I am using Xcode 5 and know that the array needs to be 180 in length. In your AppDelegate.h file - @property(nonatomic,retain) NSMutableArray *sharedArray; In AppDelegate.m @synthesize sharedArray; In didFinishLaunchingWithOptions - sharedArray = [[NSMutableArray alloc]init]; Now, make create shared object of AppDelegate like- mainDelegate = (AppDelegate *)[

Avoid copying NSMutableArray for reading with multithreaded writes

ⅰ亾dé卋堺 提交于 2019-11-29 10:52:07
I have a class that uses a mutable array that is modified once after a lot of reads (new items arrive). The problem is that when times comes to mutate the array, reads keep coming. Currently to avoid this issue every time it reads something it does so over a copy: [[theArray copy] operation] //operation being indexOfObject:, objectAtIndex: objectsAtIndexes:, etc. The copy is becoming really expensive, especially when there is no need to (all those times when the array is not being mutated). How can I lock the array to delay the access to it when is being mutated? Put all your array accesses

How to sort an array which contains Dictionaries?

家住魔仙堡 提交于 2019-11-29 10:47:09
问题 I have an array which contains dictionaries in it; so how can I sort the array according to dictionary key values? 回答1: If every element in the array is a dictionary containing a certain key, you can sort the array using a sort descriptor. For instance, if every element is a dictionary containing a key called "name": NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:sortByName]; NSArray

How do you store data from NSMutable Array in Core Data?

帅比萌擦擦* 提交于 2019-11-29 10:41:48
The app i'm making draws a Polyline based on the users coordinates from CLLocationManager (these are all kept in an NSMutableArray ) When the app closes, the current polyline disappears. How can I store the array of points in CoreData to be retrieved when the app starts up? All of the past 'routes' that the user has taken since initiating the app should be recovered and overlaid on the map (which may be quite a lot, so CoreData seems the best option from what i've gathered). This is the code I use to create an MKPolyline from the loaded coordinates -(IBAction)didClickLoadCoordinates:(id)sender

Collection <__NSArrayM: 0x7fa1f2711910> was mutated while being enumerated

雨燕双飞 提交于 2019-11-29 10:35:20
问题 There are number of questions with similar title but none them of helped me. but i can relate solution of this 'NSGenericException', reason: Collection <__NSArrayM: 0x7fabb400> was mutated while being enumerated question with my question. Because this termination is happening when I'm adding,removing string object with array. Error : Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x7fa1f2711910> was mutated while being enumerated.' First

NSMutableArray Data Attachement With E-mail Body?

会有一股神秘感。 提交于 2019-11-29 08:58:47
My NSMutableArray data are in NSData formate.I am trying to attached NSMutableArray data to E-mail body.Here is my NSMutableArray code: NSUserDefaults *defaults1 = [NSUserDefaults standardUserDefaults]; NSString *msg1 = [defaults1 objectForKey:@"key5"]; NSData *colorData = [defaults1 objectForKey:@"key6"]; UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData]; NSData *colorData1 = [defaults1 objectForKey:@"key7"]; UIColor *color1 = [NSKeyedUnarchiver unarchiveObjectWithData:colorData1]; NSData *colorData2 = [defaults1 objectForKey:@"key8"]; UIFont *color2 = [NSKeyedUnarchiver

Trying to populate NSMutableArray but get implicit conversion of int to id is disallowed with arc

谁都会走 提交于 2019-11-29 08:46:52
I am simply trying to add a series of numbers to an NSMutableArray but I am getting the error: implicit conversion of int to id is disallowed with arc resultArray = [[NSMutableArray alloc]init]; for (int i = 0; i <= 9; i++) { [resultArray addObject:i]; } What am I doing wrong? An NSArray or NSMutableArray can only hold objects, not primitive data types such as int s. So if you want to add them to the array, you'll have to wrap them in an NSNumber . You can do the following: [resultArray addObject:@(i)]; This is equivalent to doing: [resultArray addObject:[NSNumber numberWithInt:i]]; 来源: https:

按首字母分组排序数组

北慕城南 提交于 2019-11-29 08:20:12
/*--> */ /*--> */ 1 2 3 // 按首字母分组排序数组 4 5 -(NSMutableArray *)sortObjectsAccordingToInitialWith:(NSArray *)arr { 6 7 8 9 // 初始化UILocalizedIndexedCollation 10 11 UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation]; 12 13 14 15 //得出collation索引的数量,这里是27个(26个字母和1个#) 16 17 NSInteger sectionTitlesCount = [[collation sectionTitles] count]; 18 19 //初始化一个数组newSectionsArray用来存放最终的数据,我们最终要得到的数据模型应该形如@[@[以A开头的数据数组], @[以B开头的数据数组], @[以C开头的数据数组], ... @[以#(其它)开头的数据数组]] 20 21 NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:sectionTitlesCount]; 22

How to Sort an NSMutableArray of Managed Objects through an object graph

六眼飞鱼酱① 提交于 2019-11-29 06:11:14
I'm new to Apple's iPhone 3.0 SDK support of Core Data and I'm relatively new to iPhone development. My question is on slightly more "complex" sorting than is covered in the docs. I suspect that I am making an incorrect, fundamental assumption. How can I sort a pre-fetched collection of managed objects by a property contained several layers deeper in the collection? Example: Farm has a 1 to many to Cowboy (Farm.cowboys) Cowboy has a 1 to 1 to Person (Cowboy.person) Person has lastName (Person.lastName) The entire object graph has been fetched and the cowboys are displayed through a UITableView

Sorting NSMutableArray By Object's Property

陌路散爱 提交于 2019-11-29 05:24:26
So this is a rather basic question regarding the best way to sort an NSMutableArray of custom objects. I have a an NSMutableArray of custom objects, each object with an NSString and NSDate that go together. I need to sort the array by the newest object (so latest NSDate ), and I'm pretty sure I could simply use NSDate compare: NSDate if this was an array of just NSDate , but since I need all objects to be sorted and not just the date, I'm not sure if I can use that method. In terms of pseudo-code, I need to: Look at individual object, determine if the current object's NSDate is the next