nsarray

How get the total sum of currency from a NSMutableArray [duplicate]

旧巷老猫 提交于 2019-12-13 11:01:21
问题 This question already has answers here : ios - How get the total sum of float from a NSMutableArray (3 answers) Closed 5 years ago . I want to sum of currency from NSMutableArray. Ex: I have an arrayA (1,234.56 , 2,345.67) and after sum items in array, I want result show: 3,580.23 to put it on the Label. Is there the way to implement this? Thanks 回答1: If the values are stored as NSNumber objects, you can use the collection operators. For example: NSArray *array = @[@1234.56, @2345.67];

How to sort an array in descending order in iPhone [duplicate]

我与影子孤独终老i 提交于 2019-12-13 10:39:18
问题 This question already has answers here : How do I sort an NSMutableArray with custom objects in it? (25 answers) Sorting an NSArray in reverse order (2 answers) Closed 5 years ago . I am trying to sort an array in descending order,I can sort array in ascending order,Here is my code to sort in ascending order, NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"year" ascending:NO]; NSArray * descriptors = [NSArray arrayWithObjects:sortDescriptor, nil]; sortedArray =

How do I search an NSArray of objects for an object whose NSString properties match another set of NSString properties? [duplicate]

别等时光非礼了梦想. 提交于 2019-12-13 10:24:04
问题 This question already has answers here : Search NSArray for value matching value (8 answers) Closed 5 years ago . So here I grab all my objects from core data and store in an NSArray: // Set up fetch request NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"BagItem"]; // Get fetched objects and store in NSArray NSArray *fetchedObjects = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error]; Each object has a title property, a size property and a

SIGABRT on NSDictionary objectAtIndex: unrecognized selector

人盡茶涼 提交于 2019-12-13 07:26:06
问题 I'm having a weird error here. I have an array named __ImageData: static NSArray *__ImageData = nil; NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageData" ofType:@"plist"]; NSData *plistData = [NSData dataWithContentsOfFile:path]; NSString *error; NSPropertyListFormat format; _ImageData = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error]; When I NSLog out the content of the array, I get

What is difference between NSArray and normal Array?

心已入冬 提交于 2019-12-13 07:16:44
问题 I am new in Objective-c. I am feeling confuse between NSArray and normal Array. Please tell me when to use NSArray and when to use normal array? 回答1: NSArray is an Objective-C object that stores a collection of NSObject s (such as NSString , NSNumber , NSDictionary , etc) Example: NSArray *myArray = @[@"String 1",@"String 2",@"String 3"]; (the above uses Objective-C literals to define an NSArray of NSStrings -- see http://clang.llvm.org/docs/ObjectiveCLiterals.html) Objective-C is built on

Parse nested JSON code in IOS

烂漫一生 提交于 2019-12-13 06:20:35
问题 I'm trying to parse the following JSON code in iOS. The JSON code consists of an array of games numbered 0 to x. I've been searching around but cant seem to find any examples which have JSON in this format. { "command":"show_my_games", "0":{"gameid":"7","foruserid":"16","againstuserid":"0","casefor":"","caseagainst":"","status":"0","argumentid":"7","againstusername":null,"forusername":"Gem","argument":"argument 1"}, "1":{"gameid":"8","foruserid":"15","againstuserid":"16","casefor":"",

Retrieving Class Object from NSArray and adding to self

家住魔仙堡 提交于 2019-12-13 05:40:45
问题 Hi im trying to retrieve an object of a specific class from an NSMutableArray, and then add it to self: eg: - (void) init{ _Objects = [[NSMutableArray alloc]init]; Psychicing *psy = [[Psychicing alloc]init]; [psy startPsychic]; [_Objects addObject: psy]; [psy release]; } This creates an object of class Psychicing, then runs the [psy startPsychic] method to create the internals of the class object. Then I add the psy object to _Objects NSMutableArray. -(void)startPsychic{ id psychicParticle =

How to send an array to a table where the user can select a friend and post to their Facebook wall

半城伤御伤魂 提交于 2019-12-13 05:27:12
问题 I'm using the following code to call the Facebook request method, the request calls the delegate method which returns an NSDictionary object with a key labelled 'data'. I then get the friends array by calling NSArray *data = [result objectForKey:@"data"]; Then the code loops through that array and extracts the names outputting them to the console. The problem I'm having is how do I send this array to a table where the user can select a friend and post to their FB wall. thanks for any help :)

ios - convert NSArray to NSDictionary

安稳与你 提交于 2019-12-13 04:19:21
问题 i want to convert an nsarray to nsdictionary i'm using to - (NSDictionary *) indexKeyedDictionaryFromArray:(NSArray *)array { id objectInstance; NSUInteger indexKey = 0; NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init]; for (objectInstance in array) [mutableDictionary setObject:objectInstance forKey:[NSNumber numberWithUnsignedInt:indexKey++]]; return (NSDictionary *)[mutableDictionary autorelease]; } output result is: { 0 = { Event = ""; ID = 1; }; 3 = { Event = ""

How save images in home directory?

安稳与你 提交于 2019-12-13 04:01:42
问题 I am making an application in which i have use Json parsing. With the help of json parsing i get photo url which is saved in string. To show images in my cell i use this code NSString *strURL=[NSString stringWithFormat:@"%@", [list_photo objectAtIndex:indexPath.row]]; NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: strURL]]; CGRect myImage =CGRectMake(13,5,50,50); UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImage]; [imageView setImage: