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
30
votes
5 answers

Store NSArray In Core Data Sample Code?

I have been searching for some sample code on how to store an NSArray in Core Data for awhile now, but haven't had any luck. Would anyone mind pointing me to some tutorial or example, or better yet write a simple sample as an answer to this…
Stunner
  • 12,025
  • 12
  • 86
  • 145
29
votes
5 answers

Sort NSArray with sortedArrayUsingComparator

In Objective-C I can sort an NSArray using this statement: NSArray *sortedArray = [persons sortedArrayUsingComparator:^NSComparisonResult(Person *p1, Person *p2) { return [p1.name compare:p2.name]; }]; I'm unable to reproduce the same statement…
Paulo Rodrigues
  • 5,273
  • 7
  • 35
  • 58
28
votes
5 answers

How to turn an NSArray of strings into an array of unique strings, in the same order?

If you have an NSArray of strings { @"ONE", @"ONE", @"ONE", "TWO", @"THREE", @"THREE" } How would I turn that into { @"ONE", @"TWO", @"THREE" } ..where the array follows the same order as the original. I think that you can turn an array into an…
cannyboy
  • 24,180
  • 40
  • 146
  • 252
28
votes
3 answers

How do I put objects in an NSArray into an NSSet?

I have some NSDictionary objects stored in an NSArray called telephoneArray. I fetch the values for the key number and then replace the NSDictionary I've just read with a new object at the same index in the array. I then want to put these new…
conorgriffin
  • 4,282
  • 7
  • 51
  • 88
27
votes
2 answers

Got a EXC_CORPSE_NOTIFY symbol crash, how to track it?

Here's the whole crash log. What's the meaning of EXC_CORPSE_NOTIFY exception notice? I have to replace some strings about our company. Incident Identifier: 40BD3A10-43A5-4F0D-A283-218E1D3BEE46 CrashReporter Key: …
kimimaro
  • 1,263
  • 2
  • 12
  • 21
27
votes
9 answers

Check if array contains part of a string in Swift?

I have an array containing a number of strings. I have used contains() (see below) to check if a certain string exists in the array however I would like to check if part of a string is in the array? itemsArray = ["Google, Goodbye, Go,…
Daniel Bramhall
  • 1,451
  • 4
  • 18
  • 24
27
votes
7 answers

Alphabetical sections in table table view in swift

I have a list of names sorted alphabetically, and now I want display these names in a table view. I'm struggling with grouping these names for each letter. My code looks like this: let sections:Array =…
martin
  • 1,894
  • 4
  • 37
  • 69
27
votes
3 answers

Is it possible to filter an NSArray by class?

Is there a way construct a predicate to filter by class type? I currently loop through the array and check to the class of each object. Maybe there is a cleaner way?
Corey Floyd
  • 25,929
  • 31
  • 126
  • 154
27
votes
7 answers

How to convert CFArray to Swift Array?

According to Apple's "Using Swift with Cocoa and Objective-C", "In Swift, you can use each pair of toll-free bridged Foundation and Core Foundation types interchangeably". This makes working with Core Foundation sound way simpler than it actually…
jeremywhuff
  • 2,911
  • 3
  • 29
  • 33
27
votes
1 answer

How to slice an NSArray in Objective-C?

What's the simplest way to extract a slice of an NSArray in Objective-C? (much like the array_slice function in PHP)
philfreo
  • 41,941
  • 26
  • 128
  • 141
27
votes
4 answers

Convert an iOS objective c object to a JSON string

I have an objective C class like, @interface message : NSObject { NSString *from; NSString *date; NSString *msg; } I have an NSMutableArray of instances of this message class. I want serialize all the instances in the NSMutableArray into a JSON…
Sankar
  • 6,192
  • 12
  • 65
  • 89
26
votes
2 answers

Objective-C For-In Loop Get Index

Consider the following statement: for (NSString *string in anArray) { NSLog(@"%@", string); } How can I get the index of string in anArray without using a traditional for loop and without checking the value of string with every object in…
The Kraken
  • 3,158
  • 5
  • 30
  • 67
26
votes
6 answers

How get the total sum of NSNumber's from a NSArray?

I have a large NSArray containing NSNumbers like 3, 4, 20, 10, 1, 100, etc... How do I get the total sum of all these NSNumbers (3 + 4 + 20 + 10 + 1 + 100 + etc...) as one total NSInteger? Thank you!
neowinston
  • 7,584
  • 10
  • 52
  • 83
25
votes
7 answers

Removing item from array by property value

I'm looking for the most efficient and memory friendly way. Let's say I have an array of Person objects. Each person has a hair color represented by an NSString. Let's then say I want to remove all Person objects from the array where their hair…
Choppin Broccoli
  • 3,048
  • 2
  • 21
  • 28
25
votes
2 answers

transactionReceipt for in-app purchase is deprecated in iOS 7. What can I replace it with?

In iOS 7, on the SKPaymentTransaction class, the property transactionReceipt: // Only valid if state is SKPaymentTransactionStatePurchased. @property(nonatomic, readonly) NSData *transactionReceipt …is deprecated. But, in my code, I created a…
user_Dennis_Mostajo
  • 2,279
  • 4
  • 28
  • 38