nsmutablearray

What is the best way to save an NSMutableArray to NSUserDefaults?

微笑、不失礼 提交于 2019-12-21 05:01:05
问题 I have a custom object called Occasion defined as follows: #import <Foundation/Foundation.h> @interface Occasion : NSObject { NSString *_title; NSDate *_date; NSString *_imagePath; } @property (nonatomic, retain) NSString *title; @property (nonatomic, retain) NSDate *date; @property (nonatomic, retain) NSString *imagePath; Now I have an NSMutableArray of Occasions which I want to save to NSUserDefaults. I know it's not possible in a straight forward fashion so I'm wondering which is the

Check if NSDictionary is empty

天涯浪子 提交于 2019-12-21 03:38:08
问题 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

What's the best way to store and retrieve multi-dimensional NSMutableArrays?

孤者浪人 提交于 2019-12-21 02:29:09
问题 I'm storing a bunch of data in a .plist file (in the application documents folder), and it's structured like this: Dictionary { "description" = "String Value", "sections" = Array ( Array ( Number, ... Number ), Array ( Number, ... Number ) ), "items" = Array ( Array ( Number, ... Number ), Array ( Number, ... Number ) ) } If I just retrieve it with NSMutableDictionary *d = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFile] I won't be able to replace the number objects, correct? So

NSMutableArray - Add array at start

China☆狼群 提交于 2019-12-20 12:36:00
问题 It is a simple pull to refresh case. I have data loaded into table and have a mutable data array at back-end, I receive a array of new data and want to add this complete array at start of existing array. One workaround is to create new array with new arrived data and then add previous array into it using addObjectsFromArray: method. Is there some workaround to add new data array to the start of previous array directly? 回答1: First, build an NSIndexSet . NSIndexSet *indexes = [NSIndexSet

How to append values to an array in Objective-C

别说谁变了你拦得住时间么 提交于 2019-12-20 10:33:30
问题 I'm doing this: for(int i=0;i>count;i++) { NSArray *temp=[[NSArray alloc]initWIthObjects]i,nil]; NSLog(@"%i",temp); } It returns to me 0,1,2,3....counting one by one, but I want an array with appending these values {0,1,2,3,4,5...}. This is not a big deal, but I'm unable to find it. I am new to iPhone. 回答1: NSMutableArray *myArray = [NSMutableArray array]; for(int i = 0; i < 10; i++) { [myArray addObject:@(i)]; } NSLog(@"myArray:\n%@", myArray); 回答2: This code is not doing what you want it to

How to populate my tableview with a mutablearray from json

こ雲淡風輕ζ 提交于 2019-12-20 07:26:37
问题 So I'm fetching data from a url which is in a json format. I'm trying to display the data in my tableview but, even though it feels simple, I can't figure out how to do it. class CompanyModel { func getJSON() { let companyArray: NSMutableArray = NSMutableArray() let requestURL: NSURL = NSURL(string: "http://localhost/Companies/JSON.php")! let urlRequest: NSMutableURLRequest = NSMutableURLRequest(URL: requestURL) let session = NSURLSession.sharedSession() let task = session.dataTaskWithRequest

access to array object

ぐ巨炮叔叔 提交于 2019-12-20 06:16:38
问题 i create an array and i initialize it with objects. i tried to get access to the array object but i get a (null). what do i do wrong? photoArray = [[NSMutableArray alloc] init]; PhotoItem *photo1 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"1.jpg"] name:@"roy rest" photographer:@"roy"]; PhotoItem *photo2 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"2.jpg"] name:@"roy's hand" photographer:@"roy"]; PhotoItem *photo3 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:

Sorting NSArray based on other Array with custom classes

此生再无相见时 提交于 2019-12-20 03:47:49
问题 I desperately need to sort an array: heres the situation, I need to rearrange / sort and replace arrays based on other an object class from another array. ParentClass :NSObject{ NSString *name; NSNumber *type; } This is the parent class, which fills up the parentArray parentArray = { parentA, parentB, parentC } This is another object class, it has ParentClass *parent. @class ParentClass; EntryClass: NSObject{ NSString *name; NSNumber *number; ParentClass *parent; } Now I have an array

Is it correct to use short syntax when initializing NSMutableArray?

自闭症网瘾萝莉.ら 提交于 2019-12-20 02:34:30
问题 Usually when we want to initialize NSMutableArray we use: NSMutableArray *mArr = [[NSMutableArray alloc] initWithObjects: @"one", @"two", @"three", nil]; But, is it correct to use syntax like: NSMutableArray *mArr = @[@"one", @"two", @"three"].mutableCopy; I understand, that it will work a couple of nanoseconds longer. But I think the second way to be way more readable and I'm ready to sacrifice those nanoseconds. Is it ok, to use this kind of construction? Does ARC clean that unused NSArray,

how to sort an NSArray of nested NSArrays by array count?

别等时光非礼了梦想. 提交于 2019-12-19 10:55:10
问题 I have an NSArray that contains nested NSArrays. Im looking for a way to sort the parent array according to the object count of the nested arrays in ascending order. so if [array1 count] is 4, [array2 count] is 2 and [array3 count] is 9, i would get : array2, array1, array3... 回答1: There are a few solutions, one of which is: NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@"@count" ascending:YES]; NSArray *sds = [NSArray arrayWithObject:sd]; NSArray *sortedArray = [array