nsmutablearray

How to wrap a Struct into NSObject

戏子无情 提交于 2019-11-26 12:00:44
问题 this is supposed to be trivial… I think, but I can\'t find a way how to wrap a Struct variable into an NSObject . Is there a method to do so? If not, how would I go about adding a struct into an NSMutableArray ? Thanks. 回答1: Hm, try to look at the NSValue at https://developer.apple.com/documentation/foundation/nsvalue You can use it like struct aStruct { int a; int b; }; typedef struct aStruct aStruct; Then sort of "wrap" it to an NSValue object like: aStruct struct; struct.a = 0; struct.b =

NSMutableArray addObject: -[__NSArrayI addObject:]: unrecognized selector sent to instance

北城以北 提交于 2019-11-26 11:59:57
问题 I have tried to initialize my NSMutableArray 100 ways from Sunday, and NOTHING is working for me. I tried setting it equal to a newly allocated and initialized NSMutableArray, just allocating, initializing the variable by itself, every combination I could think of and always the same result. Here\'s the code: Object.h NSMutableArray *array; @property (copy) NSMutableArray *array; Object.m @synthesize array; if ( self.array ) { [self.array addObject:anObject]; } else { self.array =

iOS: store two NSMutableArray in a .plist file

[亡魂溺海] 提交于 2019-11-26 11:30:45
问题 I want to store two NSMutableArray that I use as global array in AppDelegate. These two array are also store with NSUserDefaults. Now I want to know how I must create this file and how can I store these two array everytime I modify them. Can You help me? 回答1: Create an NSArray containing your two NSMutableArrays. NSArray *array = [NSArray arrayWithObjects:<#(id), ...#>, nil]; Write the array to a file. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask,

How will I be able to remove [NSNull Null] objects from NSMutableArray?

筅森魡賤 提交于 2019-11-26 11:29:57
问题 I need to remove Null object added by [mutArrSkills addObject:[NSNull null]]; Do I need to iterate? Is there any function to remove all null values from NSMutableArray? If need to Iterate, how will I do that? 回答1: You can use NSMutableArray's removeObjectIdenticalTo: method, as follows [mutArrSkills removeObjectIdenticalTo:[NSNull null]]; to remove the null values. No need to iterate. 回答2: removeObjectIdenticalTo: Removes all occurrences of a given object in the array. Discussion This method

Removing duplicates from NSMutableArray

元气小坏坏 提交于 2019-11-26 09:58:02
问题 I have this problem with removing duplicate objects from an array. I tried these already: noDuplicates = _personalHistory.personalHistory; for (int i=[noDuplicates count]-1; i>0; i--) { if ([noDuplicates indexOfObject: [noDuplicates objectAtIndex: i]]<i) [noDuplicates removeObjectAtIndex: i]; } for (PersonalHistory_artikels *e in _personalHistory.personalHistory) { if (![noDuplicates containsObject:e]) { NSLog(@\"Dubplicates\"); [noDuplicates addObject:e]; } } for (i=0; i<_personalHistory

Rebuild an NSArray by grouping objects that have matching id numbers?

百般思念 提交于 2019-11-26 09:43:27
问题 I have an NSArray and each object in the array has a groupId and a name. Each object is unique but there are many with the same groupId. Is there a way i can tear the array apart and rebuild it so that the names are grouped into a single object with the corresponding groubId? Here is what the array currently looks like: 2013-03-12 20:50:05.572 appName[4102:702] the array: ( { groupId = 1; name = \"Dan\"; }, { groupId = 1; name = \"Matt\"; }, { groupId = 2; name = \"Steve\"; }, { groupId = 2;

Avoiding “NSArray was mutated while being enumerated”

只谈情不闲聊 提交于 2019-11-26 09:39:09
问题 I have an NSMutableArray that stores mousejoints for a Box2d physics simulation. When using more than one finger to play I\'ll get exceptions stating NSArray was mutated while being enumerated I know this is because I\'m deleting objects from the array while also enumerating through it, invalidating the enum. What I want to know is what is the best strategy to solve this going forward? I\'ve seen a few solutions online: @synchronized , copying the array before enumerating or putting the touch

Finding Intersection of NSMutableArrays

纵然是瞬间 提交于 2019-11-26 08:20:20
问题 I have three NSMutableArray containing names that are added to the lists according to different criterieas. Here are my arrays pseudocode: NSMutableArray *array1 = [@\"Jack\", @\"John\", @\"Daniel\", @\"Lisa\"]; NSMutableArray *array2 = [@\"Jack\", @\"Bryan\", @\"Barney\", @\"Lisa\",@\"Penelope\",@\"Angelica\"]; NSMutableArray *array3 = [@\"Jack\", @\"Jerome\", @\"Dan\", @\"Lindsay\", @\"Lisa\"]; I want to find a fourth array which includes the intersection of those three arrays. In this case

&#39;Invalid update: invalid number of rows in section 0

a 夏天 提交于 2019-11-26 08:02:16
问题 I\'ve read all of the related posts regarding this and I am still having an error: \'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (5) must be equal to the number of rows contained in that section before the update (5), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).\' Here

How do copy and mutableCopy apply to NSArray and NSMutableArray?

蓝咒 提交于 2019-11-26 06:58:59
问题 What is the difference between copy and mutableCopy when used on either an NSArray or an NSMutableArray ? This is my understanding; is it correct? // ** NSArray ** NSArray *myArray_imu = [NSArray arrayWithObjects:@\"abc\", @\"def\", nil]; // No copy, increments retain count, result is immutable NSArray *myArray_imuCopy = [myArray_imu copy]; // Copys object, result is mutable NSArray *myArray_imuMuta = [myArray_imu mutableCopy]; // Both must be released later // ** NSMutableArray **