nsarray

Passing array between view controllers?

99封情书 提交于 2019-12-17 19:56:45
问题 I really need some more help! I am trying to pass an array from one view controller to another. I think the latter being a 'child' view controller? My code is as follows: MainViewController.h: #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> #import <AVFoundation/AVFoundation.h> @interface HelloWorldIOS4ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, AVAudioPlayerDelegate> { NSMutableArray *countProductCode; UIPopoverController

How to perform binary search on NSArray?

末鹿安然 提交于 2019-12-17 18:49:40
问题 What is the simplest way to do a binary search on an (already) sorted NSArray ? Some potential ways I have spotted so far include: The use of CFArrayBSearchValues (mentioned here) - would this work on an NSArray ? The method indexOfObject:inSortedRange:options:usingComparator: of NSArray assumes the array is sorted and takes an opts param of type NSBinarySearchingOptions - does this mean it performs a binary search? The docs just say: Returns the index, within a specified range, of an object

Encode NSArray or NSDictionary using NSCoder

喜你入骨 提交于 2019-12-17 18:37:49
问题 I was wondering whether or not it is possible to use the NSCoder method: - (void)encodeObject:(id)objv forKey:(NSString *)key to encode either an instance of NSArray or NSDictionary. If not how do you go about encoding them? I am trying to use NSKeyedArchived / NSKeyedUnarchiver to send data between phones using GameKit. I tried it and cannot seem to retrieve the string I stored in my array. The packet class I made comes through along with the packet type integer, but not the data in the

Objective C: how to check if variable is NSArray or NSMutableArray

无人久伴 提交于 2019-12-17 18:18:14
问题 How can i check if a variable is an NSArray or an NSMutableArray? 回答1: *Note that the implementation of NS{,Mutable}Array has changed since this answer was written. As a result, isKindOfClass: now works. On what platforms where and when, I don't know. Until it is documented as safe to do so, I would strongly recommend NOT writing code that tries to detect whether a collection is mutable or immutable. Even if it were safe, such a design pattern is almost always indicative of a serious design

How to get the last object of an NSArray

一曲冷凌霜 提交于 2019-12-17 18:14:56
问题 So I have an array which the amount of items could vary. I was wondering if there is anyway I can get the last object of an NSArray ? I did think of having like an int counter to trace the amount of items in the array however that seems too much of a hassle. Does anyone know anyway that's better than this? 回答1: Expanding a bit on the question, there are several situations in which one could need the last object of an array, with different ways to obtain it. In a straight Cocoa program If one

Sorting a NSArray

ⅰ亾dé卋堺 提交于 2019-12-17 17:59:18
问题 I have a NSArray of objects. Those objects have an int attribute called "distance". I would like to sort my array by distance. Could someone please tell me how to do that ? I can't understand how the sortUsingSelector or sortUsingDescriptor methods are working... Thanks 回答1: I assume you're using an NSMutableArray, because an NSArray is immutable. When you sort something, you want the end result to be arranged as x1 <= x2 <= x3 <= x4 <= ... <= xN How to define this <= ? There are 3 solutions

NSDictionary to NSArray?

…衆ロ難τιáo~ 提交于 2019-12-17 17:56:23
问题 i have a NSDictionary which looks like: { "Item1" = 2.4; "Item2" = 5.5; "Item3" = 15.6; } To use this NSDictionary Items in a Table View i have to transfer it to a NSArray , am i right? So i try: NSDictionary *dict = [myDict objectForKey:@"items"]; for (id item in dict) { [_myArray addObject:[dict objectForKey:item]]; } But _myArray keeps empty? What am i doing wrong? 回答1: Leaving aside the technical issues with the code you posted, you asked this: To use this Dictionary Items in a Table View

Disadvantage of using NSMutableArray vs NSArray?

最后都变了- 提交于 2019-12-17 17:54:27
问题 I'm using an array to store cached objects loaded from a database in my iPhone app, and was wondering: are there any significant disadvantages to using NSMutableArray that I should know of? edit: I know that NSMutableArray can be modified, but I'm looking for specific reasons (performance, etc..) why one would use NSArray instead. I assume there would be a performance difference, but I have no idea whether it's significant or not. 回答1: If you're loading objects from a database and you know

Deep Copy and Shallow Copy

爱⌒轻易说出口 提交于 2019-12-17 17:38:44
问题 I have read the answer for difference between deep copy and shallow copy from the post, What is the difference between a deep copy and a shallow copy? . Now I got some doubt that when we made a shallow copy by newArray = [NSmutableArray arrayWithArray:oldArray]; the new array will point to oldArray. (As from the figure). Now what happen when I remove object from newArray? As from figure, it should remove same element from oldArray too !!! It seems like newArray = oldArray is a shallow copy

NSArray with NSPredicate using NOT IN

狂风中的少年 提交于 2019-12-17 17:36:52
问题 I have an NSArray that I want to filter out certain objects using an NSPredicate, I was hoping I could use NOT IN since I saw that I can easily do an IN. So I have my array: self.categoriesList Then I get the values I want to remove: NSArray *parentIDs = [self.cateoriesList valueForKeyPath:@"@distinctUnionOfObjects.ParentCategoryID"]; This gives me a list of ParentCategoryID's for categories I DO NOT want to display, so I figure I can use an NSPredicate to remove them: self.cateoriesList =