nsarray

iPhone dev - create array in init or viewDidLoad

空扰寡人 提交于 2019-12-01 04:20:23
问题 In my UIViewController subclass should I initialize the NSArray of data for the UIPickerView in init or in viewDidLoad and why? Thanks. 回答1: I would call it in viewDidLoad as the view can be loaded more than once (and also be unloaded, hence you might also want to reload your array). Also, it's a good idea to load data lazily on iPhone most of the time. Loading data in viewDidLoad is much lazier than init , which might end up performing better for you if you init, but don't immediately use

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

Create a NSSet from NSArray based on property

不问归期 提交于 2019-12-01 03:53:48
How does one create a NSSet of objects from an array based on a property. e.g. Array of objects, each with a strong reference to a type property, and multiple occurrences of each type exist in the array. How can this be turned into an NSSet holding a single object of each type. NSSet *distinctSet = [NSSet setWithArray:[array valueForKeyPath:@"@distinctUnionOfObjects.property"]]; A dictionary essentially has this functionality already. Its keys are a set, so you can create the dictionary to hold the objects, keyed by whatever attribute you're interested in: [NSDictionary dictionaryWithObjects

How to slice an NSArray in Objective-C?

会有一股神秘感。 提交于 2019-12-01 02:07:20
What's the simplest way to extract a slice of an NSArray in Objective-C? (much like the array_slice function in PHP) Ole Begemann -[NSArray subarrayWithRange:] Reference: https://developer.apple.com/documentation/foundation/nsarray/1415157-subarraywithrange 来源: https://stackoverflow.com/questions/1752955/how-to-slice-an-nsarray-in-objective-c

iPad large NSArray - initWithObjects vs. ArrayWithObjects

末鹿安然 提交于 2019-12-01 01:08:55
can anyone clear this up for me ? I am building an iPad App that has a TableViewController that is supposed to show something between 1000 and 2000 strings. I have those NSStrings in a Singleton. In the init Method of the Singleton I initialize an Array that holds all the data ( does not have to be the final way to do it - was just a quick copy and paste for testing ) I did an self.someArray = [[NSArray alloc]initWithObjects: followed by the large number of strings, followed by nil. that worked fine in the simulator - but crashed with bad access on the iPad right on Application startup If I

Create a NSSet from NSArray based on property

拟墨画扇 提交于 2019-12-01 00:59:29
问题 How does one create a NSSet of objects from an array based on a property. e.g. Array of objects, each with a strong reference to a type property, and multiple occurrences of each type exist in the array. How can this be turned into an NSSet holding a single object of each type. 回答1: NSSet *distinctSet = [NSSet setWithArray:[array valueForKeyPath:@"@distinctUnionOfObjects.property"]]; 回答2: A dictionary essentially has this functionality already. Its keys are a set, so you can create the

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]; //

How do I format a text file to be read in using arrayWithContentsOfFile

痞子三分冷 提交于 2019-12-01 00:19:45
I have several large word lists and I had been loading them in place in the code as follows: NSArray *dict3 = [[NSArray alloc] initWithObjects:@"abled",@"about",@"above",@"absurd",@"absurdity", ... but now it is actually causing an exc_bad_access error weirdly, i know it seems implausible but for some reason IT IS causing it. (trust me on this I just spend the better part of a day debugging this crap) Anyway, I'm looking to get these humongous lines of code out of my files but I'm not sure what the best approach is. I guess I could do a plist but I need to figure out how to automate the

NSArray initialization methods

孤人 提交于 2019-11-30 23:30:08
What is the difference between initializing array with NSArray * array = [NSArray array]; and NSArray * array = @[]; NSArray * array = @[]; is the new way of doing NSArray * array = [NSArray array]; @[] is shorthand for: id a = nil; NSArray* array = [NSArray arrayWithObjects:&a count:0]; Which is really just shorthand for [NSArray array] , for all intents and purposes. This is a feature added in a particular version of the compiler (and doesn't actually require runtime support for this particular syntax). It is not at all like the @"" shorthand in that @"" produces a compile time constant and

Want smooth transition or slide between pictures in an NSArray using UISwipeGesture

吃可爱长大的小学妹 提交于 2019-11-30 22:17:42
I have a UIImageView as one of my tabbarcontroller views, and I've added a UISwipeGestureRecognizer (right and left) to navigate through a series of photos in an NSArray. However, when swiping it jumps from photo to photo with no smooth transition. I'm not after anything fancy, but even a slide animation would be okay, like as one photo slides in, the other is sliding out the other side. Is this possible with the UISwipeGestureRecgonizer and an NSArray? The standard solution is to use a UIScrollView with pagingEnabled = YES and multiple image views inside the scroll view. If you want to work