nsarray

NSArray size and mutability

最后都变了- 提交于 2020-01-05 09:45:14
问题 In Java, I commonly initialize arrays that are a specific size and then add and replace objects as my code goes on. In Objective C, I can't do that with an NSArray. Code that I have ported over from Java often has to use NSMutableArray, which I assume perform less efficent than NSArray. (My best guess as to how NSMutableArray stores it's members is using a linked list, but I could be wrong) Are there any types of arrays for Objective C that have fixed sizes and allow changes within the array?

Multiple NSMutableArrays, one sorted by Predicate, others reordered relatively

南笙酒味 提交于 2020-01-05 07:37:28
问题 I have a Music App I am developing, and while I'm managing the TableViews, I'm sorting them into Sections. This is usually an easy process, but the with the way I manage I manage the data, it might not be a completely simple task. I know it's not the best way to do it, but as the cell has multiple properties (titleLabel, textLabel, imageView), I store all the data in 3 separate arrays. When organising the songs by title, for section header, I use a predicate to set the titleLabel, so by using

Showing value from NSArray on the basis of other NSArray

耗尽温柔 提交于 2020-01-05 04:05:15
问题 (My english is not good). I have two NSArray. EXAMPLE: 1st NSArray is storing NSArray category= { ID:1,Name:Category1;ID:2, Name: Category2;ID:3, Name:Category3;} 2nd NSArray is storing NSArray product= {cat_ID:1, Category-Name:Category1, product_ID:1, Name: Banana; cat_ID:1, Category-Name:Category1, product_ID:2, Name: apple; cat_ID:1, Category-Name:Category1, product_ID:3, Name: berry; cat_ID:2, Category-Name:Category2, product_ID:4, Name: cantaloupe; cat_ID:2, Category-Name:Category2,

NSArray: Why is SIGABRT sent instead of an 'index out of bounds' kind of error?

 ̄綄美尐妖づ 提交于 2020-01-05 01:36:31
问题 Ok. So I had this extremely weird SIGABRT error on a complex Objective-C iOS program that I'm working on, and after one day of tracking I found the culprit. Let's say we have the following code: NSArray *a = [NSArray arrayWithObjects:@"a", @"b", @"c", nil]; NSLog(@"tada: %@", [a objectAtIndex:-1]); Why the hell will this terminate the program with Program received signal: SIGABRT and the debugger not even pointing to my code (but rather in some assembly part) instead of a nicer 'index out of

doubleValue does not convert the object to a double value correctly at all times

爷,独闯天下 提交于 2020-01-04 06:35:21
问题 I have an NSArray in which I would like to store double values. I defined it as follow NSMutableArray *setOfDoubles; I add the elements as follow NSNumber *num; num = [NSNumber numberWithDouble:someDouble]; [setOfDoubles addObject:num]; And I read the element as follow num = [setOfDoubles lastObject]; [setOfDoubles removeLastObject]; doubleValueToUse = [num doubleValue]; My problem is sometimes (Not always), for example when num (as an object) is 5.1, doubleValueToUse (as a double value) is 5

Adding individual UIImageViews for each item in an array

微笑、不失礼 提交于 2020-01-03 05:09:09
问题 I am trying to add a individual UiImageView for each item in an array this is what I have so far _shapeArray = [NSArray arrayWithObjects:@"cloud.png",@"star.png", nil]; for (int i = 0; i < [_shapeArray count]; i++){ // I make a UIImage, which I will draw later UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[_shapeArray objectAtIndex:i]]]; UIImageView* blockView = [[UIImageView alloc] initWithImage:image]; blockView.frame = CGRectMake(arc4random()%320, arc4random()%460,

remove duplicate valuse from NSMutable array [duplicate]

十年热恋 提交于 2020-01-02 08:50:32
问题 This question already has answers here : The best way to remove duplicate values from NSMutableArray in Objective-C? (14 answers) How to compare and merge NSMutableArray (2 answers) Closed 6 years ago . I am trying to remove any duplicates from my sorted array... I thought I could do it using an example from another question of mine but it turns out to not even come close to working. its a pretty horrible attempt, but its the only way i can figure out how to compare two elements of a single

How to convert Data of Int16 audio samples to array of float audio samples

烈酒焚心 提交于 2020-01-02 06:34:15
问题 I'm currently working with audio samples. I get them from AVAssetReader and have a CMSampleBuffer with something like this: guard let sampleBuffer = readerOutput.copyNextSampleBuffer() else { guard reader.status == .completed else { return nil } // Completed // samples is an array of Int16 let samples = sampleData.withUnsafeBytes { Array(UnsafeBufferPointer<Int16>( start: $0, count: sampleData.count / MemoryLayout<Int16>.size)) } // The only way I found to convert [Int16] -> [Float]... return

NSDictionary's allKeys array messed up - not in the order they are in the dictionary?

☆樱花仙子☆ 提交于 2020-01-02 04:11:43
问题 in my project I'm pulling data from a .plist, more concretely from an NSDictionary. I init a dictionary with the contents of the .plist, which works well. When I then do NSArray *array = [dict allKeys]; it fills the array with all the keys, but in a totally random order, different to the order they are in the .plist file. I would really need to preserve the order. The keys in the dictionary are arrays, if that could cause a problem. What am I not getting? Thanks a lot in advance! 回答1: Much

Sorting an nsarray of strings not string based

依然范特西╮ 提交于 2020-01-01 11:35:09
问题 So i have an array that i retrieve from a web service in no particular order example: 0 => x large, 1 => large, 2 => XX large, 3 => small, 4 => medium, 5 => x small I need to sort them: firstly based on specific - which could be reverse alphabetic: small medium large Secondly i need to sort them based on their 'x' counter parts: x small small medium large x large xx large I know i can do this with brute force string matching but i would really like a suggestion on how to do this tidily,