nsmutablearray

ios sort array with dictionaries

橙三吉。 提交于 2019-12-03 16:55:25
I have an NSMutablearray, populated by dictionaries [from a JSON request] i need to organize the array depending to a key in the dictionaries the dictionary IdReward = 198; Name = "Online R d"; RewardImageUrl = "/FileStorimage=1206"; WinRewardPoints = 250; so the array is composed by different dictionaries with the above form, and I need to organize by maximum to minimum WinRewardPoints I have seen this answer in SO, but dont understand yet how to adopt it for my case, thanks a lot! Sirji IdReward = 198; Name = "Online R d"; RewardImageUrl = "/FileStorimage=1206"; WinRewardPoints = 250;

NSMutableArray thread safety

大憨熊 提交于 2019-12-03 14:04:40
问题 In my app I'm accessing and changing a mutable array from multiple threads. At the beginning it was crashing when I was trying to access an object with objectAtIndex , because index was out of bounds (object at that index has already been removed from array in another thread). I searched on the internet how to solve this problem, and I decided to try this solution .I made a class with NSMutableArray property, see the following code: @interface SynchronizedArray() @property (retain, atomic)

NSMutableArray - Get Arrays Index Integer By Searching With A String

青春壹個敷衍的年華 提交于 2019-12-03 12:27:00
I have been working with NSMutableArray and have had no problems retrieving an object from an array by using objectAtIndex:int . Rather then pulling an object out of the array by an integer is their a way to get the index position by searching the array with a string. animalOptions = [[NSMutableArray alloc] init]; //Add items [animalOptions addObject:@"Fish"]; [animalOptions addObject:@"Bear"]; [animalOptions addObject:@"Bird"]; [animalOptions addObject:@"Cow"]; [animalOptions addObject:@"Sheep"]; NSString * buttonTitle = [animalOptions objectAtIndex:1]; // RETURNS BEAR int * objectIndex =

Can I put different types of objects in the same NSMutableArray?

蓝咒 提交于 2019-12-03 11:09:12
I have classes A and B. Can I put these classes in the same NSMutableArray without problems in future? Example: NSMutableArray *maincoll = [[NSMutableArray alloc] init]; ClassA *ca = [[classA alloc] init]; ClassB *cb = [[classB alloc] init]; //here is case [maincoll addObject:ca]; [maincoll addObject:cb]; ... Yes. No limitations. The only thing you have to be careful of is when you retrieve items from the array to verify their class (if necessary) before starting to use them. Yes. This may be the shortest answer I've ever posted. You can put objects of different classes. They just need to

NSKeyedArchiver and NSKeyedUnarchiver with NSMutableArray

回眸只為那壹抹淺笑 提交于 2019-12-03 11:04:26
问题 I'm hoping this isn't something to do with the fact that I'm using a Mutable array here, but this one is baffling me so it wouldn't surprise me if that were the case. BACKGROUND: I have made a small database which is essentially an NSMutableArray containing custom objects, which we can call recordObjects. I set up the array: database = [[NSMutableArray alloc] init]; and my custom object, called "recordObject" contains the following variables and inits: NSString *name; int anInt; Bool aBool; I

iOS-汉字排序

折月煮酒 提交于 2019-12-03 10:53:09
* 在IOS开发过程中,排序是我们经常遇到的问题,那么如何进行排序呢? * 在英文状态下,系统中有直接可以调用的方法。 例如:对数组[sss, aaa, bbb, ppp]进行排序,我们可以直接使用系统方法。 NSMutableArray * array = [[NSMutableArray alloc]initWithObjects:@"sss",@"aaa",@"bbb",@"ppp",nil]; array = (NSMutableArray *)[array sortedArrayUsingSelector:@selector(compare:)]; NSLog(@"%@",array); 上面代码的运行结果为:aaa, bbb, ppp, sss * 但是如果上面的数组中出现汉语字符,排序就会出现问题,那么在汉语数组中如何进行排序呢? 在汉字字符串排序,因为编码问题,不能直接对汉字字符串进行直接排序。 想要对汉字进行排序,我们需要做一下准备。 1.将汉字转化成相应的拼音。 2.根据拼音将汉字排序。 一:汉字转化成相应的拼音:(例如:"编码改变世界"要转化成“bianmagaibianshijie”) 将汉语转化成拼音,有很多方法,有第三方库实现,也有系统自带的方法实现。 第三方转化的比较常用的是由George编写的,使用起来比较方便

Check if NSDictionary is empty

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 10:40:57
I want to check if an NSDictionary is empty. I am doing it like this. mutDictValues = [[[NSUserDefaults standardUserDefaults] objectForKey:@"dicValues"]mutableCopy]; NSLog(@"dictValues are %@",mutDictValues); if(mutDictValues == NULL){ arrCities = [[NSMutableArray alloc]init]; NSLog(@"no cities seleceted"); }else{ arrCities = [[NSMutableArray alloc]init]; arrCities = [mutDictValues objectForKey:@"cities"]; [self placeCities]; } But it alwasy crashes on this line arrCities = [mutDictValues objectForKey:@"cities"]; with the following error: -[__NSCFConstantString objectForKey:]: Can someone help

Sorting NSMutablearray by NSString as a date

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an array, which is filled out with string objects. Inside each object is the name of the object and the string, seperated by " - ", ex. "Object1 - 26.05.2012 ". I would like to sort my array by the date in the string, and not the name, descending Is this possible? 回答1: As @Vladimir pointed out, it would be much better to separate the name and the string from each other and sort by the date. NSMutableArray * newArray = [[ NSMutableArray alloc ] init ]; NSDateFormatter * formatter = [[ NSDateFormatter alloc ] init ]; [

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 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