nsarray

NSPredicate 'OR' filtering based on an NSArray of keys

霸气de小男生 提交于 2019-12-03 13:01:13
Consider the following NSArray: NSArray *dataSet = [[NSArray alloc] initWithObjects: [NSDictionary dictionaryWithObjectsAndKeys:@"abc", @"key1", @"def", @"key2", @"hij", @"key3", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"klm", @"key1", @"nop", @"key2", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"qrs", @"key2", @"tuv", @"key4", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"wxy", @"key3", nil], nil]; I am able to filter this array to find dictionary objects that contain the key key1 // Filter our dataSet to only contain dictionary objects with a key of 'key1' NSString *key =

Loop through NSDictionary to create separate NSArrays

人盡茶涼 提交于 2019-12-03 12:06:02
问题 I have a large NSDictionary that I need to loop through and create separate NSArray s. Here are the contents: ( { id = { text = ""; }; sub = { text = " , "; }; text = ""; "thumb_url" = { text = ""; }; title = { text = "2010-2011"; }; type = { text = "title"; }; }, { id = { text = "76773"; }; sub = { text = "December 13, 2010"; }; text = ""; "thumb_url" = { text = "http://www.puc.edu/__data/assets/image/0004/76774/varieties/thumb.jpg"; }; title = { text = "College Days - Fall 2010"; }; type =

How to convert CFArray to Swift Array?

和自甴很熟 提交于 2019-12-03 10:55:18
问题 According to Apple's "Using Swift with Cocoa and Objective-C", "In Swift, you can use each pair of toll-free bridged Foundation and Core Foundation types interchangeably". This makes working with Core Foundation sound way simpler than it actually is... I am trying to work with a CFArray that is returned from CoreText. I have this code: let lines: CFArrayRef = CTFrameGetLines(frame) I see two possible ways to access members of this array. Neither is working for me right now. Way #1 - Use the

Why zone is always nil while implementing NSCopying?

守給你的承諾、 提交于 2019-12-03 10:32:09
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]]; 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 zones is quite correct. Zones were originally created -- first NXZone, then NSZone -- to ensure that objects

CALayerArray was mutated while being enumerated

六月ゝ 毕业季﹏ 提交于 2019-12-03 10:08:07
I have to delete an object of an array every now and then, when I do it I get this error. Collection < CALayerArray: 0xc4f3b20> was mutated while being enumerated The error appears on this method, which is the accesor of the Array: - (NSArray *)occupantsArray { if (dispatch_get_current_queue() == moduleQueue) { return occupantsArray; } else { __block NSArray *result; dispatch_sync(moduleQueue, ^{ //ON THIS LINE result = [occupantsArray copy]; }); return [result autorelease]; } } As you can see Im taking care of not returning the original array but a copy, but it still crashes. Also the method

How to add an NSMutableArray to an NSMutableArray Objective-c

谁都会走 提交于 2019-12-03 09:52:56
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? August Lilleaas 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 . Since an array is just an object like any other: [myContainerMutableArray addObject:someOtherArray]; Or if you want

How do I get a list of countries in Swift ios?

家住魔仙堡 提交于 2019-12-03 09:52:04
I've already seen two similar questions to mine, but the answers for those questions do not work for me. I have an old project with a list of countries manually typed out inside a set of square brackets. I can easily use this in my pickerView but I'm wondering if there is a more efficient way to do this? I will be using the list of countries in a UIPickerView. Ian You can get a list of countries using the NSLocale class's isoCountryCodes which returns an array of [String] . From there, you get the country name by using NSLocale 's displayName(forKey:) method. It looks like this: var countries:

How to convert NSArray to NSMutableArray

╄→гoц情女王★ 提交于 2019-12-03 09:50:33
ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); NSMutableArray *tempPeoples=[[NSMutableArray alloc]init]; for(int i=0;i<nPeople;i++){ ABRecordRef i1=CFArrayGetValueAtIndex(allPeople, i); [tempPeoples addObject:i1]; // [peoples addObject:i1]; }// end of the for loop peoples=[tempPeoples copy]; This code gives exception b/c I want to convert NSMutableArray to NSArray Please Help sean woodward The subject reads, "How to convert NSArray to NSMutableArray ". To

Differences between [NSArray arrayWithArray:] and [NSArray copy]

匆匆过客 提交于 2019-12-03 09:50:31
lately I work much with arrays and I'm wonder.. what's diffrences between those two lines. NSArray *array = [NSArray arrayWithArray:someArray]; and NSArray *array = [someArray copy]; Which of it is faster? What in case we have NSMutableArray and mutableCopy ? Which of it is faster? Don't worry about it. Premature optimization. The main difference: the first approach results in an autoreleased "copy" that you don't own and don't have to release, while you do own the object created on the second line. Both arrays will be immutable, by the way. In addition to the other answers, also note, that

How get the total sum of NSNumber's from a NSArray?

泄露秘密 提交于 2019-12-03 09:36:21
I have a large NSArray containing NSNumbers like 3, 4, 20, 10, 1, 100, etc... How do I get the total sum of all these NSNumbers (3 + 4 + 20 + 10 + 1 + 100 + etc...) as one total NSInteger ? Thank you! NSInteger sum = 0; for (NSNumber *num in myArray) { sum += [num intValue]; } You can use this: NSArray* numbers = //array of numbers NSNumber* sum = [numbers valueForKeyPath: @"@sum.self"]; fabrice truillot de chambrier long long sum = ((NSNumber*)[array valueForKeyPath: @"@sum.longLongValue"]).longLongValue; Iterate through the array int count = [array count]; NSInteger sum = 0; for (int i = 0;