nsarray

How do I check if an object exists at a certain index of an NSMutableArray?

混江龙づ霸主 提交于 2019-12-10 12:55:08
问题 For instance, how could I verify if there is an item at the index 3? The objects in the NSArray are instantiated from the class "Animal." 回答1: Well, since NSMutableArray has to hold non-nil objects, as long as the array is big enough, you know there's something at index i : if ([myArray count] > 3) { id myObj = [myArray objectAtIndex:3]; ... } If you needed to check something elsek, like say make sure it didn't have a reference to the NSNull singleton, you could then check if (myObj !=

How to determine an array index in Objective C?

蹲街弑〆低调 提交于 2019-12-10 12:39:50
问题 I have two arrays in Objective C and I need to find what index something is so I can insert it in the same place. For instance, lets say I have a "name array" and an "age array". How do I find out what index "charlie" is in the "name array" so I know where to insert his age in the "age" array? Thanks 回答1: -[NSArray indexOfObject:] would seem to be the logical choice. 回答2: In Cocoa, parallel arrays are a path to doom and ruination. You can't use them effectively with Bindings, so you'll have

Access an NSArray from Every View Controller

三世轮回 提交于 2019-12-10 12:25:50
问题 I have a quite big NSArray , that i have to use in several view controllers. I get the data from a server and i don't wanna download it always when the user opens a new view. So how can i define it as a "global variable"? I can do it with segues, but without them it's not working. I've tried to declare an array called dataToDestinationView in the DestinationViewController , then imported it to the view where the self.arrayToExport is and add the lines above, but doesn't worked. Do i missed

Sort NSArray by date and time

空扰寡人 提交于 2019-12-10 12:04:50
问题 This may be a duplicate question, but i have a strange issue, So that i have pasted it on stack. I have a issue while sorting NSArray by date and time. For example, I have below fields in Database file:- id Name Date 1 ABC 2015-01-29 16:36:31 2 AAA 2015-01-29 16:36:31 3 BBB 2015-01-29 16:36:31 4 CCC 2015-01-29 16:36:31 5 DDD 2015-01-29 16:36:31 Note :- Datatype of Date filed is Timestamp in sqlite Database and i am storing it as NSDate while fetching data. Now, I am sorting this data as below

Find indices of duplicates in a NSArray

为君一笑 提交于 2019-12-10 11:49:27
问题 i have an array like [chapter,indent,left,indent,nonindent,chapter,chapter,indent,indent,left]; i need to find indexes of duplicates and also non duplicate elements . how to do this...........give some sample code or logic...... thanks in advance iam using objective c..... NSArray *myWords = [string componentsSeparatedByString:@"class=\""]; int count_var=[myWords count]; tmp1=@""; for(int i=1;i<count_var;i++) { str=[NSString stringWithFormat:@"\n%@",[myWords objectAtIndex:i]]; class=[str

iPhone sdk: how to delete duplicates in the NSArray

房东的猫 提交于 2019-12-10 11:48:43
问题 Hi My NSArray contains duplicates like this(i have to delete the duplicates) titles: Father's Day titles: Father's Day titles: Father's Day titles: Election Day titles: Election Day titles: Election Day titles: Easter titles: Easter titles: Earth Day titles: Earth Day titles: Earth Day titles: Cinco de Mayo titles: Cinco de Mayo titles: Cinco de Mayo titles: Christmas Eve titles: Christmas Eve titles: Christmas Eve titles: Christmas titles: Christmas titles: Christmas I have keep one name

How to parse Dictionary with keys that have array of dictionaries

我的梦境 提交于 2019-12-10 11:19:06
问题 UPDATE-8/31/12- So now I would need to go through the Array of Dictionaries based on "isReservable" = 1 and then display the "begin". I am just trying to get the contents of the array of each dictionary and I can go from there (for now). Below is what I have tried. Thanks to everyone for the help I am learning more everyday. json from php page { "slots": { "2012-08-31 00:00:00 America/Los_Angeles": [ { "isPending": false, "isReservable": true, "isReserved": false, "label": " ", "begin": "2012

Creating a NSArray from a C Array

℡╲_俬逩灬. 提交于 2019-12-10 09:30:46
问题 There are many threads about going the opposite way, but I am interested in converting from a primitive C array to a NSArray. The reason for this is that I want to create a NSString from the array contents. To create the NSString I will use: NSArray *array; NSString *stringFromArray = [array componentsJoinedByString:@","]; I am joining the elements of the array by commas because I will later be saving the string as a .csv file. I don't think it matters, but the C array I am dealing with is of

Predicate to filter array of strings in SWIFT throws error saying NSCFString is not key-value coding

独自空忆成欢 提交于 2019-12-10 04:24:37
问题 Below is my code snippet //Search Bar Delegate func searchBar(searchBar: UISearchBar, textDidChange searchText: String) { println(searchText) var predicate:NSPredicate=NSPredicate(format: "SELF CONTAINS[c] \(searchText)")! self.listItemToBeDisplayed=listItem.filteredArrayUsingPredicate(predicate) (self.view.viewWithTag(1) as UITableView).reloadData() } Error I got: *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x17405ef90> valueForUndefinedKey:

How to sort NSArray with date time values?

不打扰是莪最后的温柔 提交于 2019-12-10 00:33:04
问题 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? 回答1: 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