nsmutablearray

iPhone app crash [__NSCFString objectForKey:] unrecognized selector sent to instance

女生的网名这么多〃 提交于 2019-11-28 10:50:42
问题 I am trying to add in tempArray only even number of data.localBookmarks is array of dictionary. Here is my code : currentIndex = indexPath.row; for (NSDictionary *dict in localBookmarks) { if (currentIndex % 2 == 0 && currentIndex <= [localBookmarks count]) { [tempArray addObject:[dict objectForKey:@"firstName"]]; } currentIndex++; } NSLog(@"tempArray %@",tempArray); cell.textLabel.text = [tempArray objectAtIndex:indexPath.row]; return cell; my app crash on [tempArray addObject:[dict

NSArray - check if objects are in an array?

左心房为你撑大大i 提交于 2019-11-28 10:00:03
问题 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? 回答1: Are you sure that you need NSArray s? For

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

被刻印的时光 ゝ 提交于 2019-11-28 09:29:50
问题 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 ? 回答1: In general, when you

How to make an CFArrayRef to an NSMutableArray

风格不统一 提交于 2019-11-28 08:34:50
问题 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); 回答1: A CFArrayRef is toll-free bridged to NSArray * , so you can cast it as such and then create a mutable copy: NSMutableArray *data = [(NSArray *)

NSMutableArray removeObjectAtIndex strange issue.

。_饼干妹妹 提交于 2019-11-28 07:49:37
问题 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

Shuffling an array in objective-c [duplicate]

不羁的心 提交于 2019-11-28 07:44:25
Possible Duplicate: What’s the Best Way to Shuffle an NSMutableArray? I develop apps for iphone/iPad.I want to shuffle the objects stored in an NSArray.Is there any way to achieve it with objective-c? Saurabh Add a category to NSMutableArray, with code provided by Kristopher Johnson - // NSMutableArray_Shuffling.h #if TARGET_OS_IPHONE #import <UIKit/UIKit.h> #else #include <Cocoa/Cocoa.h> #endif // This category enhances NSMutableArray by providing // methods to randomly shuffle the elements. @interface NSMutableArray (Shuffling) - (void)shuffle; @end // NSMutableArray_Shuffling.m #import

Objective C: how to check if variable is NSArray or NSMutableArray

我怕爱的太早我们不能终老 提交于 2019-11-28 06:52:34
How can i check if a variable is an NSArray or an NSMutableArray? *Note that the implementation of NS{,Mutable}Array has changed since this answer was written. As a result, isKindOfClass: now works. On what platforms where and when, I don't know. Until it is documented as safe to do so, I would strongly recommend NOT writing code that tries to detect whether a collection is mutable or immutable. Even if it were safe, such a design pattern is almost always indicative of a serious design flaw. (For those with access) Filed rdar://10355515 asking for clarification. Consider: int main (int argc,

Type of class in a NSMutableArray [duplicate]

百般思念 提交于 2019-11-28 06:18:42
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is there any way to enforce typing on NSArray, NSMutableArray, etc.? I'm Java programmer and I'm starting on Obj-C, in java i can create a mutable array with determined type of class, like as follow: ArrayList<MyClass> list; in Obj-c I know the NSMutableArray but i don't know and not found how to determinate the type of class into it. Have a way of make this with it or other class without NSMutableArray which

Disadvantage of using NSMutableArray vs NSArray?

五迷三道 提交于 2019-11-28 05:46:10
I'm using an array to store cached objects loaded from a database in my iPhone app, and was wondering: are there any significant disadvantages to using NSMutableArray that I should know of? edit: I know that NSMutableArray can be modified, but I'm looking for specific reasons (performance, etc..) why one would use NSArray instead. I assume there would be a performance difference, but I have no idea whether it's significant or not. If you're loading objects from a database and you know exactly how many objects you have, you would likely get the best performance from NSMutableArray s

Set bool property of all objects in the array

烂漫一生 提交于 2019-11-28 05:43:03
问题 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