nsmutablearray

How to search through a NSMutableArray

主宰稳场 提交于 2019-12-10 13:23:44
问题 I have a NSMutableArray that I need to search for a string and return the key in the array where the string was found. So for example if I'm searching "ipod" and it's the 4th in the array, it would return 3 or whatever position the string is in. What's the best way to do this? 回答1: return [theArray indexOfObject:@"ipod"]; Reference: http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/indexOfObject:

Sorting mutable array by dictionary key

无人久伴 提交于 2019-12-10 13:08:15
问题 I have already looked through a few answers using the various sorting methods of NSMutableArray , but for some reason they are not working for me. I am just trying to sort the mutable array which contains dictionaries by the Delay key within each dictionary. However, the "sorted" array is the exact same as the original array. By the way, it works fine if I create a dummy mutable array and populate it with dictionaries containing numbers, but for some reason it won't sort this mutable array

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

well using NSXMLParser the values inside an array are all set to the last entry

房东的猫 提交于 2019-12-10 11:57:02
问题 I use an NSXMLParser to parse YouTube's API and I get all the content I want and put it into a class called Video. When I am writing to the class from inside parserDidEndElement and I end that video I write the class to an NSMutableArray . Then I NSLog the title of the video that was logged into the array. This is different for each video. I use the addObject: method to add videos to the array. However when I use parserDidEndDocument I use a for loop to read through the array and all of the

Convert NSString to NSArray [duplicate]

一曲冷凌霜 提交于 2019-12-10 11:08:31
问题 This question already has answers here : Comma-separated string to NSArray in Objective-C (2 answers) Closed 6 years ago . I have one string as follows: NSString *str = @"abcd,efgh"; Now I want to convert this string into NSMutableArray like NSMutableArray *arr = {abcd,efgh}; then how can I do this? any help would be appreciated. 回答1: NSArray *arr = [@"abcd,efgh" componentsSeparatedByString:@","]; should do the job. 来源: https://stackoverflow.com/questions/15271450/convert-nsstring-to-nsarray

How to persist a NSMutableArray

99封情书 提交于 2019-12-10 10:24:20
问题 I'm absolutely new to iOS Dev. I started out with the really helpful tutorial on Apple dev website So i made the simple To-Do List application, as per instructions. The App: It's a simple to-do list. It has a view, with a single text-field, which takes in an input, which then appends that input to the table-list view. the table list view is my "TO-Do List" which is generated from a NSMutableArray. The Problem: Whenever i quit and relaunch the application, my List disappears. The Question: I

CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull

↘锁芯ラ 提交于 2019-12-10 05:23:05
问题 For some reason this sample code works: NSArray *immutable = @[ @"a", @"b", @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers); and this code produces nil as a result of the conversion: NSArray *immutable = @[ @"a", [NSNull null], @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable,

[UIImageView _isResizable]: unrecognized selector sent to instance SIGABRT

烂漫一生 提交于 2019-12-10 03:32:40
问题 I've got this code trying to run a simple set of images in a cycle. All I have in the app is one UIImageView declared in my View Controller's .h file: @property (strong, nonatomic) IBOutlet UIImageView *imageDisplay; And the following in my .m file's viewDidLoad method: NSMutableArray *imageView = [[NSMutableArray alloc] init]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim1.png"]]]; [imageView addObject:[[UIImageView alloc] initWithImage:[UIImage

How to create an NSMutableArray and assign a specific object to it?

て烟熏妆下的殇ゞ 提交于 2019-12-10 02:06:19
问题 I am just getting into Obj C, and I am looking to create an array of MKAnnotations. I have already created the MKAnnotation class called TruckLocation that contains the name, description, latitude, and longitude. Here is what I have so far for the array: NSMutableArray* trucksArray =[NSMutableArray arrayWithObjects: @[<#objects, ...#>] nil]; 回答1: Yore trying to combine 2 different syntaxes for similar but different things. You also don't seem to have any instances of your annotations. Create

sorting mutable array in alphabetical order

荒凉一梦 提交于 2019-12-09 23:12:55
问题 I am having a nsmutable array and in that nearly 50 -60 object having different names ,and can i sort this array in alphabetical order (Is it possible, How?) 回答1: For a simple sort like this, I like to use sort descriptors. Suppose you have an mutable array of objects whose class has a name NSString property: NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:NO]; [myArray sortUsingDescriptors:[NSArray arrayWithObject:sort]]; 回答2: Absolutely, you can use