nsmutablearray

NSArray - check if objects are in an array?

这一生的挚爱 提交于 2019-11-29 16:07:31
I have 2 arrays. One is a large static group of 600 objects, the other is a small varying group of 10 objects. I want to take any common objects between the two groups and put them in a new array. So lets say the large group contains 600 objects named 1 to 600. The smaller group contains 9 objects: 1, 2, 3, 4, 5, 6, a, b, c. I want to be able to create a new array that contains the objects 1, 2, 3, 4, 5, 6. What is the best way to do this? Are you sure that you need NSArray s? For intersections it would be better to use NSSet s. For more information about the usage of NSArrays and NSSet please

Why can I send messages to a deallocated instance of NSArray?

懵懂的女人 提交于 2019-11-29 15:53:15
I just noticed a surprising behavior of NSArray , that's why I'm posting this question. I just added a method like: - (IBAction) crashOrNot { NSArray *array = [[NSArray alloc] init]; array = [[NSArray alloc] init]; [array release]; [array release]; } Theoretically this code will crash. But In my case it never crashed !!! I changed the NSArray with NSMutableArray but this time the app crashed. Why this happens, why NSArray not crashing and NSMutableArray crashes ? In general, when you deallocate an object the memory is not zeroed out, it’s just free to be reclaimed by whoever needs it.

Cannot add object to an NSMutableArray array

雨燕双飞 提交于 2019-11-29 14:47:46
@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 (count--) { if ([[[self.simataDataController objectSimataInListAtIndex:count] categoryCode] isEqual

How to make an CFArrayRef to an NSMutableArray

梦想的初衷 提交于 2019-11-29 14:45:44
This is my Code to create the CFArrayRef. I want to know how to make it to an NSMutableArray. I need it for my TableViewController. Or is there another way to use the CFArrayRef in the TableViewController? ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef arrayOfAllPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); A CFArrayRef is toll-free bridged to NSArray * , so you can cast it as such and then create a mutable copy: NSMutableArray *data = [(NSArray *) myCFArrayRef mutableCopy]; For an autoreleased version, use NSMutableArray* data = [NSMutableArray arrayWithArray:

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

牧云@^-^@ 提交于 2019-11-29 14:30:35
问题 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 removeObjectAtIndex strange issue.

夙愿已清 提交于 2019-11-29 13:51:56
Strange behaviour in NSMutableArray . I've created object and filled it. NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4", nil]; [array removeObjectAtIndex:0]; Before removing it looks like: array NSMutableArray * 0x1040b5e0 [0] id 0x00088a44 @"1" [1] id 0x00088a54 @"2" [2] id 0x00088a64 @"3" [3] id 0x00088a74 @"4" After removing FIRST element: array NSMutableArray * 0x1040b5e0 [0] id 0x00000000 [1] id 0x00088a54 @"2" [2] id 0x00088a64 @"3" What am i doing wrong here? Are you using lldb for debugging? Try gdb if so. lldb has known bugs of this nature where it

how to compare two NSMutableArray?

老子叫甜甜 提交于 2019-11-29 12:39:34
问题 How can I compare two NSMutableArray ? if both are same than it should return true otherwise false. Thanks... 回答1: return ([array1 isEqualToArray:array2]); returns YES if arrays are equal else returns NO 回答2: Does isEqualToArray: method help you? Other way is to iterate through both arrays and compare each object using isEqual: method. It is the same to calling isEqualToArray: . Note that in both variants you should implement isEqual: method in your array object class if it in not a standard

iOS error: [__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]

末鹿安然 提交于 2019-11-29 12:10:59
In my application I try to load contents from a url, store them in a mutable array and show them in a table view. But I can't get it working, because every time I run the app this error appears: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]' *** First throw call stack: (0x34dd088f 0x36d9e259 0x34d2823d 0x316e562f 0x315f09a9 0x313c0c5d 0x313c1b95 0x313c1ae7 0x313c16c3 0xa5cfb 0x33623ec7 0x35387a09 0x35390051 0x33622965 0xa4dc1 0x313a8e33 0x313cd629 0x31391d7d 0x314544dd 0x3139a55d 0x3139a579 0x3139a40b

Set bool property of all objects in the array

霸气de小男生 提交于 2019-11-29 12:02:57
I've a model class called PhotoItem . In which I have a BOOL property isSelected @interface PhotoItem : NSObject /*! * Indicates whether the photo is selected or not */ @property (nonatomic, assign) BOOL isSelected; @end I've an NSMutableArray which holds the object of this particular model. What I want to do is, in a particular event I want to set the bool value of all objects in the array to true or false. I can do that by iterating over the array and set the value. Instead of that I tried using: [_photoItemArray makeObjectsPerformSelector:@selector(setIsSelected:) withObject:[NSNumber

How to add alive object to NSMutableArray and remove them when they're released?

两盒软妹~` 提交于 2019-11-29 11:13:51
I have class Item and class List (which has an NSMutableArray). Every time class Item is instantiated (and destroyed) it posts a notification, which is listened-to by class List. When class List receives the notification is adds the instance of class Item to its list. I'm trying to have class Item also post a notification that its about to be dealloc'd. The problem is that class List's NSMutableArray retains the instance of class Item. What's the most appropriate means of handling this situation? If I decrement the count when adding it to List's array, then an exception will be thrown when