Tag: nsarray

select indexOfObject from NSArray in Xcode by comparing string

Hi I have NSarray values in Xcode. I need to get array indexOfObject by comparing string values. my array values are ( { firstName = lord; lastname = krishna; }, { firstName = priya; lastname = amirtha; } ) If I type first name in textfield and click button means last name want to display […]

Getting UITableView to populate with data from another class

I am quite new to Objective-C and this is the first time I have attempted to implement MVC. I have a model class where l have an NSArray which will be populated with data from a JSON object. I want to populate my UITableView (in my view controller class), with objects from this array. Please […]

CALayerArray was mutated while being enumerated

I have to delete an object of an array every now and then, when I do it I get this error. Collection < CALayerArray: 0xc4f3b20> was mutated while being enumerated The error appears on this method, which is the accesor of the Array: – (NSArray *)occupantsArray { if (dispatch_get_current_queue() == moduleQueue) { return occupantsArray; } […]

Pick closest NSNumber from array

I have an array with a bunch of NSNumbers. From an UISlider I get a certain value when the user stops dragging it. I would like to get the closes number from the array. So for instance, if the user drags the UISlider to 13, and the NSArray contains the NSNumbers with 10 and 15; […]

Comparing NSMutableArray Elements for Values

I am looking for a way to compare the contents of two NSMutableArray objects. Both arrays are filled with NSMutableDictionaries which were allocated separately but occasionally contain the same data. Simplified Example: NSMutableArray *firstArray = [[NSMutableArray alloc] init]; NSMutableArray *secondArray = [[NSMutableArray alloc] init]; NSMutableDictionary *a = [[NSDictionary alloc] init]; [a setObject:@”foo” forKey:”name”]; [a setObject:[NSNumber […]

Calculate possible permutations of an array of numbers

I have an NSArray with the numbers {0,1,2,3} Calculating the factorial of 4 (the count of the array), I have 24 possible permutations of 0,1,2,3 I would like to know if there is a way to calculate all of these possible permutations and place them in a separate array. For example, given the numbers above, […]

Convert JSON to NSArray

I have a JSON array being output on a page. I would like to convert this JSON array into an NSArray. This is the JSON output on the web page: [{“city”:”Current Location”},{“city”:”Anaheim, CA”},{“city”:”Los Angeles, CA”},{“city”:”San Diego, CA”},{“city”:”San Francisco, CA”},{“city”:”Indianapolis, IN”}] This is my NSURL call and NSJSONSerialization: NSString *cityArrayURL = [NSString stringWithFormat:@”http://site/page.php”; NSData *cityData = […]

Sorting an nsarray of strings not string based

So i have an array that i retrieve from a web service in no particular order example: 0 => x large, 1 => large, 2 => XX large, 3 => small, 4 => medium, 5 => x small I need to sort them: firstly based on specific – which could be reverse alphabetic: small medium […]

Searching a NSArray for the nearest number(s)

Is there an easy way to search an NSArray of numbers to find the nearest (or exact if it exists) matches to a user-input number? Say I have an array like this: 7, 23, 4, 11, 18, 2, and the user enters 5. The program returns the three nearest values in descending order of closeness: […]

Strange behavoir when decoding an NSArray via NSSecureCoding

i spent all afternoon banging my head against the wall trying to figure out why decoding of this class was failing. the class has a property that is an NSArray of Foo objects. Foo conforms to NSSecureCoding, and i have successfully encoded and decoded that class by itself. i was getting an error in initWithCoder: […]