Questions tagged [nsarray]

An immutable, integer-indexed array of objects from the Apple Foundation framework.

An NSArray object manages an immutable array; once you have created the array, you cannot add, remove, or replace the objects in the array. You can, however, modify the individual elements themselves (if they support modification). The mutability of the collection does not affect the mutability of the objects inside the collection. You should use an immutable array if your data rarely changes, or changes all at once. Consider using a mutable array () if your data changes frequently.

Resources:

5346 questions
36
votes
5 answers

How to stop enumerateObjectsUsingBlock Swift

How do I stop a block enumeration? myArray.enumerateObjectsUsingBlock( { object, index, stop in //how do I stop the enumeration in here?? }) I know in obj-c you do this: [myArray enumerateObjectsUsingBlock:^(id *myObject,…
random
  • 8,568
  • 12
  • 50
  • 85
35
votes
3 answers

What is __NSArrayI and __NSArrayM? How to convert to NSArray?

What is __NSArrayI and __NSArrayM? __NSArrayI(or M) cause "unrecognized selector" error. How to convert to NSArray? I did test to parse json, twitter api. http://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=twitterapi ==> works fine.…
ChangUZ
  • 5,380
  • 10
  • 46
  • 64
34
votes
7 answers

Serialize and Deserialize Objective-C objects into JSON

I need to serialize and deserialize objective-c objects into JSON to store in CouchDB. Do people have any example code for best practice for a general solution? I looked at a few JSON framework and they are stopped at the NSDictionary/NSArray…
PokerIncome.com
  • 1,708
  • 2
  • 19
  • 30
34
votes
3 answers

checking if an array doesn't contain a certain object

is there a class available to check if an array doesn't contain an object? I want to do something like if [(myarray doesntContain @"object")] is this possible
Alex Stelea
  • 1,219
  • 2
  • 18
  • 29
34
votes
11 answers

NSDictionary to NSArray?

i have a NSDictionary which looks like: { "Item1" = 2.4; "Item2" = 5.5; "Item3" = 15.6; } To use this NSDictionary Items in a Table View i have to transfer it to a NSArray, am i right? So i try: NSDictionary *dict = [myDict…
phx
  • 1,509
  • 3
  • 15
  • 18
33
votes
5 answers

Disadvantage of using NSMutableArray vs NSArray?

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…
igul222
  • 8,557
  • 14
  • 52
  • 60
33
votes
7 answers

Compiler error "expected method not found" when using subscript on NSArray

I wrote this simple code to try out the new Objective-C literal syntax for NSArrays: NSArray *array = @[@"foo"]; NSLog(@"%@", array[0]); The first line works fine, but the subscripting results in an error: Expected method to read array element…
33
votes
5 answers

Subtract objects in one NSArray from another array

I have two NSArrays: NSArray *wants = [NSArray arrayWithObjects: @"apples", @"oranges", @"pineapple", @"mango", @"strawberries", …
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
32
votes
2 answers

NSArray from NSSet - Do I have to sort it myself?

I've got data in an NSSet, and I need to get it into an NSArray. Do I need to sort it myself (again, this came from Core Data) or can I get it out in a sorted order?
Jeff
  • 4,751
  • 5
  • 31
  • 35
32
votes
3 answers

What is the NSObject isEqual: and hash default function?

I have a database model class that is a NSObject. I have a set of these objects in a NSMutableArray. I use indexOfObject: to find a match. Problem is the model object's memory address changes. So I am overriding the hash method to return the model's…
Brenden
  • 7,708
  • 11
  • 61
  • 75
32
votes
13 answers

How to create a NSString from a format string like @"xxx=%@, yyy=%@" and a NSArray of objects?

Is there any way to create a new NSString from a format string like @"xxx=%@, yyy=%@" and a NSArray of objects? In the NSSTring class there are many methods like: - (id)initWithFormat:(NSString *)format arguments:(va_list)argList -…
Panagiotis Korros
  • 10,840
  • 12
  • 41
  • 43
31
votes
3 answers

Converting NSArray to NSMutableArray

As above. Would be helpful to know. Thanks!
Sidwyn Koh
  • 1,742
  • 2
  • 21
  • 29
31
votes
5 answers

NSArray find object or objects - best practices

Solution: I have marked @BlackRider's answer as correct as it is the most versatile especially for complex comparisons however there are other very good answers and comments. I would encourage anyone with the same or similar question to review them…
Uptown Apps
  • 707
  • 1
  • 5
  • 11
30
votes
2 answers

How to sort NSArray of objects based on one attribute

I am trying to sort an array of managed objects alphabetically. The attribue that they need to be sorted by is the name of the object (NSString) with is one of the managed attributes. Currently I am putting all of the names in an array of strings…
Jackelope11
  • 1,181
  • 4
  • 15
  • 31
30
votes
5 answers

Convert JSON feed to NSDictionary

Where JSON_CATEGORY_DATA_URL_STRING is my feed URL, which returns fine as: [ { "group":"For Sale", "code":"SSSS" }, { "group":"For Sale", "category":"Wanted", "code":"SWNT" } ] I cannot seem…
linkingarts
  • 325
  • 1
  • 3
  • 8