nsmutabledictionary

How to set Dictionary in NSUserDefault in swift?

房东的猫 提交于 2019-12-02 08:16:30
问题 I've a mutable dictionary (in form of [Int:Int]) and want that to save it. I would use NSUserDefaults like that: var myDic: NSMutableDictionary = [:] myDic = [1:2] NSUserDefaults.standardUserDefaults().setObject(myDic, forKey: "myDic") but with that I get an error: Thread 1: signal SIGABRT I have no idea why. 回答1: setObject(_:forKey:) can’t accept Dictionary with a key which is integer type. The method requires property-list objects, but myDic = [1:2] is not property-list object. There are

Getting Top 10 Highest Numbers From Array?

感情迁移 提交于 2019-12-02 07:17:18
I am having a bit of a issue. I have an NSMutableDictionary with 10 NSMutableArrays in it. Each array has somewhere between 0-10 numbers which could each be any integer, e.g. 12 or 103. What I need to do is get the top 10 highest numbers from across each of the arrays. The trouble is, I need to keep a reference of the array it came from in the dictionary (the key) and the index position of the number from the array it came form. Easiest way, is to sort the array in Descending order, and then grab the first 10 indexes Or if they are inside dictionaries, iterate the dictionary allValues , grab

How to save a NSMutableDictionary into a file in documents?

为君一笑 提交于 2019-12-02 05:59:50
I would like to save the content of a NSMutableDictionary object to a file. How do I do this ? I already know how to do this task with a NSDictionary object but I don't know how to convert/copy this NSMutableDictionary to a NSDictionary...unless there's a method to write directly the content of NSMutableDictionary to a file...I stress that the NSMutableDictionary object contains objects of NSDictionary type. Thx for helping, Stephane NSMutableDictionary is a subclass of NSDictionary : you can use it anywhere you'd use NSDictionary . Literally, just pass the object through to the same code you

iPhone: preserve NSUserDefaults values when application is killed

前提是你 提交于 2019-12-02 04:40:40
I am trying to implement "Add to Favorites" functionality using NSUserDefaults. So far I have written following code. - (void)favouriteButtonClicked:(id)sender { favselected = !favselected; // favselected is BOOL property MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; NSString* viewname = @"custom"; if(favselected) { [favButton setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateNormal]; [appDelegate addTOFavourites:self.ViewID viewType:self.ViewType]; } else { [favButton setBackgroundImage:[UIImage imageNamed:@"unselected

How to set Dictionary in NSUserDefault in swift?

随声附和 提交于 2019-12-02 04:24:05
I've a mutable dictionary (in form of [Int:Int]) and want that to save it. I would use NSUserDefaults like that: var myDic: NSMutableDictionary = [:] myDic = [1:2] NSUserDefaults.standardUserDefaults().setObject(myDic, forKey: "myDic") but with that I get an error: Thread 1: signal SIGABRT I have no idea why. setObject(_:forKey:) can’t accept Dictionary with a key which is integer type. The method requires property-list objects, but myDic = [1:2] is not property-list object. There are two documents about it. setObject(_:forKey:) of NSUserDefaults The value parameter can be only property list

iOS — distinguish an NSDictionary from an NSMutableDictionary?

时光怂恿深爱的人放手 提交于 2019-12-01 23:32:44
I have the following code fragment: NSString* value = @"value"; NSString* key = @"key"; NSMutableDictionary* foo = [NSMutableDictionary dictionary]; NSDictionary* bar = [NSDictionary dictionary]; NSAssert([bar isKindOfClass: [NSMutableDictionary class]], @""); // passes the assert as both are NSCFDictionary; NSAssert([bar respondsToSelector: @selector(setValue:forKey:)], @""); // passes the assert because it NSCFDictionary does respond to the selector [foo setValue:value forKey:key]; // no problem, foo is mutable [bar setValue:value forKey:key]; // crash So if I have an object which is either

Problems with adding objects to NSMutableDictionary

↘锁芯ラ 提交于 2019-12-01 23:13:49
问题 I am making an iPhone app and I am loading information from a server. I send NSURLRequest to the server and get back a NSString value. This is working fine and the value I am getting back is the correct one. The problem is that when I try to add the value for the variable to a NSMutableDictionary I have made to store the values, it doesn't work. When I debug and look at the values of the NSMutableDictionary in Xcode it says 0 key/value pairs right after the line where I add the values. This

Problems with adding objects to NSMutableDictionary

萝らか妹 提交于 2019-12-01 21:34:34
I am making an iPhone app and I am loading information from a server. I send NSURLRequest to the server and get back a NSString value. This is working fine and the value I am getting back is the correct one. The problem is that when I try to add the value for the variable to a NSMutableDictionary I have made to store the values, it doesn't work. When I debug and look at the values of the NSMutableDictionary in Xcode it says 0 key/value pairs right after the line where I add the values. This is what my code looks like: NSArray *varsToLoad = [fixedData objectForKey:@"varsToLoad"]; NSError *error

How to get NSMutableDictionary count in iphone?

十年热恋 提交于 2019-12-01 15:13:46
I want to get NSMutableDictionary count in iphone. I want to know how many items are in NSMutableDictionry. I tried these code to find out the solution but, not helped me lot. NSLog(@"Count : %d", [mutableDictionary count]); It is always returns '0'. How to get the count of NSMutableDictionary in iPhone? Thanks in advance. You can find out how many key-object (key-value) pairs there are like so: NSArray * allKeys = [mutableDictionary allKeys]; NSLog(@"Count : %d", [allKeys count]); EDIT Upon looking through the dictionary documentation, NSDictionary 's count method (or property) should work as

how to change order of NSMutable array in same way another mutable arrays get changed

泄露秘密 提交于 2019-12-01 14:53:13
I have three arrays . They are name , birthdates and remaining days like below: name birthdate remaining "Abhi Shah", "01/14", 300 "Akash Parikh", "12/09/1989", 264 "Anand Kapadiya", "12/01", 256 "Annabella Faith Perez", "03/02", 347 "Aysu Can", "04/14/1992", 25 "Chirag Pandya" "10/07/1987" 201 I want to rearrange the remaining days array into ascending order, but at the same time name and birthdate should also get reordered in the same way. See this example below: name birthdate remaining "Aysu Can", "04/14/1992", 25 "Chirag Pandya" "10/07/1987" 201 "etc..." self.arrayForRows = [