Tag: arrays

Objective C – Sort an array of string

I have to sort an array of objects by a property of the objects that is a string. How can I do this?

2D Array Declaration – Objective C

Is there a way to declare a 2D array of integers in two steps? I am having an issue with scope. This is what I am trying to do: //I know Java, so this is an example of what I am trying to replicate: int Array[][]; Array = new int[10][10]; Now, in OBJ-C I want […]

Passing an int array of variable length as a function parameter in Objective C

I have the following code which works fine… int testarr[3][3] = { {1,1,1}, {1,0,1}, {1,1,1} }; [self testCall: testarr]; Which calls this function: – (void)testCall: (int[3][3]) arr { NSLog(@”cell value is %u”,arr[1][1]); } I need the array to be of variable length – What is the best way to declare the function? Using blanks doesn’t […]

RLMObject with Array of NSStrings

I’ve been upgrading a project to use Realm as the persistence store and I’m not able to find any documentation on how to use an array of strings in one of my models. The implementation of an Array for a RLMObject is to use an RLMArray where T inherits RLMObject I could make an object […]

Adding Integer To NSMutableArray

I couldn’t find this anywhere, so I am asking just asking to make sure. And yes, I know its basic, but I figure I’d rather get that right before I make the mistake a million times: If I do the following, does it cast the “0” to an NSNumber by default (if not, what Object […]

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)

Variable length parameters in Objective-C

How can i make a class method with variable length parameters, in Objective-C? For example, a method like -arrayWithObjects: NSArray *array = [NSArray arrayWithObjects:@”1″, @”2″, @”3″, nil];

How do I make an array of CGFloats in objective c?

So I’m working on a simple iPhone game and am trying to make a local high score table. I want to make an array and push the highest scores into it. Below is the code I have so far: CGFloat score; score=delegate.score; NSInteger currentindex=0; for (CGFloat *oldscore in highscores) { if (score>oldscore) { [highscores insertObject:score […]

How can I sort an array of strings alphabetically when the strings contains åäö?

I’m building an app in xcode4.3/Objective-C and have come across a problem when trying to sort an NSMutableArray. I’ll populate it with strings from a sqlite database. The problem occurs with the swedish characters å, ä and ö. The orded array should look something like this: as, br, ol, st, år, ög, ös. But when […]

Declaring, Properties, Synthesizing, and Implementing int array in Objective C

How do you declare, set properties, synthesize, and implement an int array of size 5 in Objective C? I’m writing this code for an iphone app. Thanks.