nsarray

Getting UITableView to populate with data from another class

风流意气都作罢 提交于 2019-12-04 20:57:33
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 review my code: Droplets.h @interface Droplets : NSObject { NSArray *dropletsArray; } // Get droplets data - (void) getDropletsList; //Object initilization - (id) init; //Public properties @property (strong, nonatomic) NSArray *dropletsArray; // Used to store the selected JSON data objects @end Droplets.m

Search NSArray of NSDictionaries

依然范特西╮ 提交于 2019-12-04 20:46:55
问题 I have an array with dictionaries, and need to search trough the array and modify a specific dictionary in the array found by an object name inside the dictionary. So , create the mutable array, dictionary , and add many dictionaries to the array ...{ self.bloquesArray = [[[NSMutableArray alloc] init]autorelease]; [self createBloqueDicto]; [self.unBloqueDicto setObject:@"easySprite" forKey:@"Name"]; [self.unBloqueDicto setObject:@"290" forKey:@"X"]; [self.unBloqueDicto setObject:@"300" forKey

Pick closest NSNumber from array

只谈情不闲聊 提交于 2019-12-04 20:02:53
I have an array with a bunch of NSNumber s. 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 ; I want to get 15 from the array. Example of array: NSArray *values = [NSArray arrayWithObjects:[NSNumber numberWithInt:15], [NSNumber numberWithInt:20], [NSNumber numberWithInt:30], [NSNumber numberWithInt:45], [NSNumber numberWithInt:60], [NSNumber numberWithInt:90], [NSNumber numberWithInt:110], nil]; How do I get

How to sort NSArray with date time values?

丶灬走出姿态 提交于 2019-12-04 19:58:55
I have an NSArray containing date/time NSStrings in the following format: 2/2/2011 2:46:39 PM 2/4/2011 11:59:47 AM … where the date is represented as month/day/year. How do I sort this NSArray making sure the newest date/times are at the top? When you’re dealing with dates, use NSDate instead of NSString . Also, it’s important to consider the time zone — does the Web service provide dates in UTC or some other time zone? You should first convert your array of strings into an array of dates. Otherwise, you’d be converting a string to a date whenever it is used for comparison, and there will be

Remove particular objects from an array based on objects from another array

好久不见. 提交于 2019-12-04 19:48:31
Setup: Have a UITableView which shows US golf courses with name, street, state etc. UITableView's data source is a NSMutableArray of objects from my class GolfCourse called allGolfCourses . Now I like to remove all west coast golf courses from allGolfCourses and create a new array called eastCoastGolfCourses . I have another NSArray with string objects of all west coast states (Abbreviations) called westCoastStates but having a hard time connecting these two. How do I iterate through allGolfCourses and remove all objects which have a state Abbreviations found in westCoastStates array?

How to compare the elements of NSArray in NSMutableDictionary?

我的梦境 提交于 2019-12-04 19:30:37
My NSMutableDictionary contains four NSArray s with their respective keys. These NSArray s are of size 2 and contain 2D coordinates. I want to get the most common coordinate among them. For example, If a coordinate is common to three arrays, it would be my first choice. How can I find that any coordinate is common to at least two arrays? Basically you want to find the pair of coordinates that has max occurences. So you can create an array of all coordinates and find its mode. NSMutableArray *allCoordinates = [NSMutableArray new]; [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj,

How do you join an NSArray of [Number numberWithChar: c]'s into an NSString?

不问归期 提交于 2019-12-04 19:14:45
When I use componentsJoinedByString , I just get a long string of digits. Edit: I realize this task is confusing. Why on earth would anyone populate an NSArray with NSNumbers if they wanted an NSString? The answer is that I'm writing an extensible unit test framework. The basic functions genNum , genBool , and genChar generate NSNumbers with random int, BOOL, and char values respectively. Then there's genArray which generates a random array using a specified generator. So to construct a random NSString, one would run genArray using the genChar generator, and transform the resulting NSArray

iCloud NSMetadata query results are blank

僤鯓⒐⒋嵵緔 提交于 2019-12-04 19:02:02
I've been working on adding icloud to my project (which is quite a pain in the buns) and I'm able to save and remove files, but I can't get a list of the files stored in iCloud. I've tried solutions from about 10 different websites (including the Apple documentation). Whenever I call [self.query startQuery]; everything seems to be working: The correct methods get called, the methods execute exactly as they should. Then when I ask for an nsarray of the files in my app's iCloud Documents directory I get two parenthesis with nothing between them (when I view in NSLog): File List: ( ) . I know for

Is NSSet faster than NSArray?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 18:46:08
i am new to iOS. Anyone know if NSSet are faster than NSArray ? Why wouldn't I always just use an NSArray ? Anyone explain me difference between NSSet and NSArray ? Vijay-Apple-Dev.blogspot.com NSSet is used to have unique objects. NSArray may have duplicate objects. NSSet is an unordered collection. NSArray is an ordered collection. NSArray is faster than NSSet for simply holding and iterating. As little as 50% faster for constructing and as much as 500% faster for iterating. if you only need to iterate contents, don't use an NSSet. When the order of the items in the collection is not

how to add new elements in array at the top of the table view

ぐ巨炮叔叔 提交于 2019-12-04 18:36:30
i am displaying array of elements in a tableview. Now i need to display some other new elements on table view. For this i try by adding new elements to array which is datasource of table view and reloading the table. Then It displaying the newly added elements but the problem is it is adding at last element of array so it displaying at the bottom of the table view. But i need to display that new value at the top of the table view. How can i done this can any one please help me. Thank u in advance. (Let me add comment if any one does n't get my question). Insert the new items at the top of your