nsarray

Why zone is always nil while implementing NSCopying?

假如想象 提交于 2019-12-04 17:28:23
问题 It may be simple question, but why implementing NSCopying protocol in my class, I get zone == nil - (id)copyWithZone:(NSZone *)zone { if (zone == nil) NSLog(@"why this is allways nil"); (...) } This is called using this method for copy array with objects. [[NSArray alloc] initWithArray:myArray copyItems:YES]]; 回答1: Kevin's and Robin's answer is the most accurate. Oscar's answer is pretty close to correct. But neither the Gnustep documentation nor logancautrell's reasons for the existence of

Comparing NSMutableArray Elements for Values

末鹿安然 提交于 2019-12-04 16:47:57
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 numberWithInt:1] forKey:"number"]; NSMutableDictionary *b = [[NSDictionary alloc] init]; [b setObject:@"bar" forKey:"name"]; [b setObject:

selecting a random objectAtIndex from NSArray

限于喜欢 提交于 2019-12-04 16:45:52
I have an NSArray which contains 10 objects from index 0 - 9. Each entry in the array is a quotation. When my user selects the 'random quote' option I want to be able to select a random entry from the array and display the text that is contained in that entry. Can anyone point me in the right direction on how to achieve this? I'd recommend you use this instead of hardcoding the 10; that way, if you add more quotations, it will work it out automatically, without you needing to change that number. NSInteger randomIndex = arc4random()%[array count]; NSString *quote = [array objectAtIndex

How to add an NSMutableArray to an NSMutableArray Objective-c

安稳与你 提交于 2019-12-04 15:46:54
问题 I am making the switch from Java to Objective-c, and I'm having some difficulty. I have searched this problem this without much success. I have an NSMutableArray that stores NSMutableArrays. How do I add an array to the array? 回答1: You can either store a reference to another array (or any type of object) in your array: [myArray addObject:otherArray]; Or concatenate the arrays. [myArray addObjectsFromArray:otherArray]; Both of which are documented in the documentation. 回答2: Since an array is

Initialize Array of Objects using NSArray

瘦欲@ 提交于 2019-12-04 15:01:39
问题 I'm pretty new to Objective-C and iOS so I've been playing around with the Picker View. I've defined a Person Class so that when you create a new Person it automatically gives that person a name and age. #import "Person.h" @implementation Person @synthesize personName, age; -(id)init { self = [super init]; if(self) { personName = [self randomName]; age = [self randomAge]; } return self; } -(NSString *) randomName { NSString* name; NSArray* nameArr = [NSArray arrayWithObjects: @"Jill Valentine

Sorting Array Using NSSortDescriptor [duplicate]

♀尐吖头ヾ 提交于 2019-12-04 13:10:57
问题 This question already has answers here : How to sort NSMutableArray of date objects (3 answers) Closed 6 years ago . I have an array of class A objects, let it be detailsArray. Class A has date, name as properties. Can any one suggest a good method to sort this array based on date? How can I use NSSortDescriptor to sort this array? I know sorting array of dictionary using NSSortDescriptor ... Any help is greatly appreciated..... 回答1: NSSortDescriptor *sortDescriptor = [NSSortDescriptor

iPhone/iOS How to load a lot of image in many folder and show in a table view?

爷,独闯天下 提交于 2019-12-04 12:55:23
I got annoying question... What if I have many image , and I want load it in to a table view And show the file name as cell's text , and the preview image is also show in the cell. When I select the cell , it will push to next view , show the big size image. That's it . I don't know how to load many folder to an array? /*********** EDIT ***********/ This is the folder I set many images inside You can see that's only one root folder ... And this is my code to load the image inside NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *filePath = [[NSBundle mainBundle]

How do I get unique values from an array

倾然丶 夕夏残阳落幕 提交于 2019-12-04 11:47:20
Please note this is for OSX, not for iOS. I have looked and tried some solutions in other SO questions, but none seem to work for me, hence this: I want to get a unique set of years out of an array. My code is this: NSMutableArray * unique = [NSMutableArray array]; NSMutableSet * processed = [NSMutableSet set]; for (yearString in yearStringArray) { if (![processed containsObject:yearString] == NO) { [unique addObject:yearString]; } [processed addObject:yearString]; } NSLog(@"unique: %@",unique ); NSLog(@"processed: %@",processed ); }]; The console returns: unique: ( ( 1941, 1942, 1943, 1945,

Swift - read plist file to an array?

限于喜欢 提交于 2019-12-04 11:31:11
问题 I have created a mini translation from English words to Spanish words. I would like to use the englishArray.plist instead of my englishArray = ["the cat"] How can I create this? I have also used a localizable.strings to retrieve the value "the cat" for "el gato" but I would like to retrieve this from englishArray.plist I started off with this but not sure if I'm on the right path let path = NSBundle.mainBundle().pathForResource("englishArray", ofType: "plist") let plistEnglishArray = NSArray

iPhone SDK Xcode - How to get all the filenames in the documents dir

£可爱£侵袭症+ 提交于 2019-12-04 11:28:58
问题 I want to get all the filenames in my application's documents folder, and place them in an NSMutableArray . Nothing more, nothing less. 回答1: There is a convenient method in NSFileManager : NSFileManager *fileManager = [[NSFileManager alloc] init]; NSArray *files = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil]; ... [fileManager release]; As of ARC you can of course drop the release statement. 来源: https://stackoverflow.com/questions/7064190/iphone-sdk-xcode-how-to-get-all