nsmutablearray

How to randomize an NSMutableArray? [duplicate]

≯℡__Kan透↙ 提交于 2019-12-01 05:11:06
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: iphone - nsarray/nsmutablearray - re-arrange in random order I have an NSMutableArray that contains 20 objects. Is there any way that I could randomize their order like when you shuffle a deck. (By order I mean their index in the array) Like if I had an array that contained: apple orange pear banana How could I randomize the order so that I could get something like: orange apple banana pear 回答1: Here's some

Compare 2 nsmutablearray and get different object to third array in ios

时间秒杀一切 提交于 2019-12-01 04:49:44
I want to compare 2 NSMutableArray and get different object into third Array . How can i do that ? Array1 can loop object . Array1 = "a", "b","c","d","a","b","c"; Array2 = "a", "b", "c"; And then result Array3 = "d"; Thanks in advance Use sets for set operations: NSSet *set1 = [NSSet setWithArray:array1]; NSMutableSet *set2 = [NSMutableSet setWithArray:array2]; [set2 minusSet:set1]; Buntylm You Can try this too. NSMutableArray *array1 = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"1", nil]; NSMutableArray *array2 = [[NSMutableArray alloc]initWithObjects:@"2",@"1", nil];

Sprite Kit iOS7 - SKNode UserData property not storing values

橙三吉。 提交于 2019-12-01 04:16:14
I would think this work work easily, however I cannot understand why my NSMutableDictionary property is not working as I would have expected. [self.testSprite.userData setValue:@"CAT" forKey:@"key"]; NSLog(@"%@", [self.testSprite.userData objectForKey:@"key"]); NSLog(@"%lu", [self.testSprite.userData count]); I am retuning (null) and 0. Is there a special trick for using the spriteNode userdata ? Thanks The userData property is initially nil. You have to create a dictionary and assign it first: self.testSprite.userData = [NSMutableDictionary dictionary]; [self.testSprite.userData setValue:@

Finding out NSArray/NSMutableArray changes' indices

主宰稳场 提交于 2019-12-01 04:08:52
I have a NSMutableArray oldArray . Now, at one point, this NSMutableArray object gets updated with another NSMutableArray , which may have more, less or same number of elements as the previous NSMutableArray . I want to compare the old and the new array for changes. What I want are two NSArray s addedArray and removedArray which will contain the indices of the elements which have been added and/or removed from the old array. This whole problem will be more clear with an example : oldArray = {@"a",@"b",@"d",@"e",@"g"}; newArray = {@"a",@"c",@"d",@"e",@"f",@"h"}; So, here the removed objects are

Find the average of an NSMutableArray with valueForKeyPath

拜拜、爱过 提交于 2019-12-01 03:58:42
问题 Currently I'm trying to find a compact way to average a matrix . The obvious solution is to sum the matrix, then divide by the number of elements. I have, however, come across a method on the apple developer website that claims this can be done in a simpler way using valueForKeyPath. This is linked here: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/KeyValueCoding/Articles/CollectionOperators.html Here is the example I'm currently working on to try and get it to work:

NSMutableArray alloc init vs NSMutableArray array

偶尔善良 提交于 2019-12-01 03:23:11
问题 What is the differece between: [[NSMutableArray alloc] init] and [NSMutableArray array] 回答1: Here in [NSMutableArray array] you don't have to release array it will be released automatically. & if you will write [NSMutableArray alloc] init] you will have to release array so [[NSMutableArray array] will be equivalent to [[[NSArray alloc] init] autorelease]; 回答2: The first remains in memory until you release it, the second lasts until the end of the run loop iteration. 回答3: NSMutableArray no

What happens if NSMutableArray is modified by multiple threads at the same time? (if the objects it contains are retained elsewhere)

霸气de小男生 提交于 2019-12-01 02:22:23
问题 I have an NSMutableArray containing many objects. What happens if a change is made to the array, while I am making a copy of the array using [NSMutableArray arrayWithArray:someArray]; Eg: If an object an object is removed from the array while the copy is being made? I'm not sure how to test this scenario. EDIT: The objects are not released (as they are retained elsewhere). I just use this array as a lookup table. 回答1: as you know, the container/collection is not guaranteed to be thread safe.

Compare 2 nsmutablearray and get different object to third array in ios

可紊 提交于 2019-12-01 02:17:38
问题 I want to compare 2 NSMutableArray and get different object into third Array . How can i do that ? Array1 can loop object . Array1 = "a", "b","c","d","a","b","c"; Array2 = "a", "b", "c"; And then result Array3 = "d"; Thanks in advance 回答1: Use sets for set operations: NSSet *set1 = [NSSet setWithArray:array1]; NSMutableSet *set2 = [NSMutableSet setWithArray:array2]; [set2 minusSet:set1]; 回答2: You Can try this too. NSMutableArray *array1 = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",

Sprite Kit iOS7 - SKNode UserData property not storing values

风流意气都作罢 提交于 2019-12-01 01:11:20
问题 I would think this work work easily, however I cannot understand why my NSMutableDictionary property is not working as I would have expected. [self.testSprite.userData setValue:@"CAT" forKey:@"key"]; NSLog(@"%@", [self.testSprite.userData objectForKey:@"key"]); NSLog(@"%lu", [self.testSprite.userData count]); I am retuning (null) and 0. Is there a special trick for using the spriteNode userdata ? Thanks 回答1: The userData property is initially nil. You have to create a dictionary and assign it

insertObject: atIndex: - index 3 beyond bounds for empty array

谁说我不能喝 提交于 2019-12-01 00:57:40
I create an array based on a dictionaries key's: factsBuiltArray = [NSMutableArray arrayWithCapacity: 6]; if ([statusDict count] == 10) { for (NSString *key in [statusDict allKeys]) { if ([key isEqualToString: @"currenciesAndConversions"]) { [factsBuiltArray insertObject:key atIndex: 0]; } else if ([key isEqualToString: @"languageAndTranslations"]) { [factsBuiltArray insertObject:key atIndex: 1]; } else if ([key isEqualToString: @"plugSize"]) { [factsBuiltArray insertObject:key atIndex: 2]; } else if ([key isEqualToString: @"timezone"]) { [factsBuiltArray insertObject:key atIndex: 3]; //