nsmutablearray

how to intersect two arrays in objective C?

不打扰是莪最后的温柔 提交于 2019-11-30 11:08:00
I have two arrays . Array1 contains 15 objects and Array2 contains 4 objects. There are 2 common objects from both array, I just want to get that resulted array of that 2 objects. It should be like intersection of two Set, but how to do in Objective C for array..? Please help. thanks. Using NSMutableSet NSMutableSet *set1 = [NSMutableSet setWithArray: array1]; NSSet *set2 = [NSSet setWithArray: array2]; [set1 intersectSet: set2]; NSArray *resultArray = [set1 allObjects]; 来源: https://stackoverflow.com/questions/12173903/how-to-intersect-two-arrays-in-objective-c

NSMutableArray stored with core data = WORKS, but after changing array DOESN'T WORK

ぐ巨炮叔叔 提交于 2019-11-30 09:53:22
I have a NSManagedObject with a NSMutableArray as attribute: @interface MyObject : NSManagedObject { } @property (nonatomic, retain) id a1; In the data model it is declared as Transformable . I left the Value Transformer field like it is with the default (in light grey) NSKeyedUnarchiveFromData . a1 is created as part of theObject: MyObject *theObject = [NSEntityDescription insertNewObjectForEntityForName:@"MyObject" inManagedObjectContext: myManagedObjectContext]; and initialized: a1 = [[NSMutableArray alloc] init]; Objects are added to a1 with [a1 insertObject:[NSNumber numberWithInt:0]

Cannot add object to an NSMutableArray array

痞子三分冷 提交于 2019-11-30 09:23:38
问题 @interface SimataDetailViewController () @property Simata *simata; @property (nonatomic, copy) NSMutableArray *simataList; @end @implementation SimataDetailViewController @synthesize simataDataController=_simataDataController; @synthesize category=_category; @synthesize simata=_simata; @synthesize simataList=_simataList; #pragma mark - Managing the detail item - (void) getSimataForCategory: (NSString *) inputCategory { unsigned count = [self.simataDataController.masterList2 count]; while

How to sort an array which contains Dictionaries?

元气小坏坏 提交于 2019-11-30 07:56:00
I have an array which contains dictionaries in it; so how can I sort the array according to dictionary key values? 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 *sortedArray = [array sortedArrayUsingDescriptors:sortDescriptors]; The other way to achieve this would be using

Sorting NSMutableArray By Object's Property

喜你入骨 提交于 2019-11-30 07:45:03
问题 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

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

人盡茶涼 提交于 2019-11-30 07:27:52
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 throw call stack: ( 0 CoreFoundation 0x00000001087b8c65 __exceptionPreprocess + 165 1 libobjc.A.dylib

Join an Array in Objective-C

风格不统一 提交于 2019-11-30 06:16:13
问题 I'm looking for a method of turning a NSMutableArray into a string. Is there anything on a par with this Ruby array method? >> array1 = [1, 2, 3] >> array1.join(',') => "1,2,3" Cheers! 回答1: NSArray *array1 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil]; NSString *joinedString = [array1 componentsJoinedByString:@","]; componentsJoinedByString: will join the components in the array by the specified string and return a string representation of the array. 回答2: The method you are looking for

NSMutableArray check if object already exists

你。 提交于 2019-11-30 03:07:10
I am not sure how to go about this. I have an NSMutableArray (addList) which holds all the items to be added to my datasource NSMutableArray. I now want to check if the object to be added from the addList array already exists in the datasource array. If it does not exist add the item, if exists ignore. Both the objects have a string variable called iName which i want to compare. Here is my code snippet -(void)doneClicked{ for (Item *item in addList){ /* Here i want to loop through the datasource array */ for(Item *existingItem in appDelegate.list){ if([existingItem.iName isEqualToString:item

Adding an object at a specific index of an NSMutableArray

扶醉桌前 提交于 2019-11-30 02:32:39
How can an object be added at a specific index of an NSMutableArray ? How is an object added to the front of the array? [myMutableArray insertObject:myObject atIndex:42]; To add an object to the front of the array, use 0 as the index: [myMutableArray insertObject:myObject atIndex:0]; Take a look at the insertObject:atIndex: method of the NSMutableArray class. Adding to the "front" of the array implies index 0. For example: NSMutableArray * array = [[NSMutableArray alloc] initWithCapacity:3]; [array addObject:@"b"]; // Contains "b" [array insertObject:@"a" atIndex:0]; // Contains "a", "b"

How to convert the NSMutableArray to CSV file on iPhone?

喜欢而已 提交于 2019-11-30 02:28:54
I am writing an iPhone application, which contains a function. It can convert the NSMutableArray to a CSV file. However, I don't know how to do. Can anyone help me to do this? Thank you very much. // ------ Update ----- Thank you for everyone reply. Actually, the array contains the objects of the elements, but I can convent it all to the array like the following (I guess it is more easy to do this). The array is NSMutableArray *csvArray and the array contains data, like the following example. csvArray[0] = First Name csvArray[1] = Last Name csvArray[2] = Phone csvArray[3] = Tom csvArray[4] =