nsmutabledictionary

Argument Type 'AnyObject' does not conform to expected type NSCopying

末鹿安然 提交于 2019-12-12 03:36:45
问题 I am trying to use NSDictionary in Swift and I am facing the above-mentioned problem. I have a dictionary of the following format: let xyz: NSMutableDictionary = ["1":[1,2,3,4,"1","n","1","2"],"2":[1,2,3,4,"+","o","6","2"]] I want to iterate over keys in the dictionary and extract the 6th element of the array. I tried the following; but did not meet with any luck: for keys in dictKeyMutableDict { let xCentVal = xyz[keys as! [NSCopying]][6] } I keep on receiving a subscript error and if I

Sort NSMutableArray

梦想的初衷 提交于 2019-12-12 01:35:07
问题 please help me I want to sort NSMutableArray and yes I can do this by NSSortDescriptor *sortPoint = [[NSSortDescriptor alloc] initWithKey:@"point" ascending:YES]; [hightScore sortUsingDescriptors:[NSArray arrayWithObject:sortPoint]]; but in NSMuatableArray(hightScore), I have 2 NSMutableDictionary like this [item setObject:@"player_name" forKey:@"name"]; [item setObject:@"100" forKey:@"point"]; and when I sort by keyword "point" that is string it give me like this 100 > 20 > 30 > 50 instead

sorting an array of object with respect to the float value [duplicate]

限于喜欢 提交于 2019-12-11 15:26:23
问题 This question already has answers here : how to sort an NSArray of float values? (3 answers) Closed last year . im working with a project , where i receive an array of object, each object has a description of type string, and a value of type CGfloat. i need to sort them by value increasingly, and store them in a dicitonary. i tried this solution, but it didn't work. How do I sort an NSMutableArray with custom objects in it? any idea how to do it? for (PNPieChartDataItem *item in items) {//

Unknown reason to receive Memory Warning

南楼画角 提交于 2019-12-11 08:28:04
问题 let me come to issue fast. There is no problem in my code so far. My only concern is Memory management. Let me make my app logic clear. When App is launched globally NSmutableDictionary is declared and nearly 300 images are added to that Dictionary with various keys and images are added using pathForResource:ofType method. After my rootViewController loaded my 35 custom UIViews are added to same global dictionary with another key.(this rootViewController will not be used often) I have 4

how to store custom objects in NSMutableDictionary?

China☆狼群 提交于 2019-12-11 08:10:18
问题 I'm new to iOS. I have a class derived from NSObject and I want to store its reference into NSMutableDictionary . How can I? e.g. @interface CustomClass : NSObject { } I want to store reference (*customClass) of this CustomClass into NSMutableDictionary . Please give me the simple way to store and retrieve it. 回答1: For that purpose, you need to use NSKeyedArchiver and NSCoder classes, as following: In your CustomClass.m file, implement the following two encoding and decoding methods : - (void

How to check dictionary value is empty or not

一曲冷凌霜 提交于 2019-12-11 02:43:20
问题 i am new to swift and facing little issue and i not understanding how to check dictionary value. func doValidate(data:Dictionary<String,AnyObject>,isEmail : String) -> Bool { if(isEmail=="signup"){ if( data["last_name"] == nil || data["email"] == nil || data["password"] == nil || data["first_name"] == nil){ return false; } else{ return true; } } } Dictionary key is always constant and every time dictionary key exists but how i can check value of data["last_name"] is empty or not? if i used

encodeWithCoder is not called in derived class of the NSMutableDictionary

杀马特。学长 韩版系。学妹 提交于 2019-12-11 00:50:00
问题 Basically I am using some open source code called OrderedDictionary that is derived from NSMutableDictionary. Then I want to save the ordered dictionary data to NSUserDefaults by adding encode and decode method to the OrderedDictionary class. However, I realized the encode and decode methods are not being called, as a result, the decoded dictionary is no longer ordered. Below is my code: @interface OrderedDictionary : NSMutableDictionary <NSCopying, NSCoding> { NSMutableDictionary *dictionary

Need JSON document that is generated to be in same order as objects inserted in NSMutableDictionary in iOS

心已入冬 提交于 2019-12-10 18:33:41
问题 I am generating a JSON document from an NSMutableDictionary that is composed of keys that point to NSStrings, as well as two keys that point in turn to other NSMutableDictionary's. My problem is that when I output the JSON document, I notice that the JSON document has the objects that I inserted in the NSMutableDictionary in a different order. For example, my present output looks like this: JSON Output: { "devicetype" : "iPhone Simulator", "os" : "6.0", "test_results" : [ { "date" : "2012-12

NSDictionary / NSMutableDictionary 及 NSArray / ...

你。 提交于 2019-12-10 15:49:13
NSDictionary 常用方法总结 +(id)dictionaryWithObjectsAndKeys:obj1,key1,obj2,key2,......nil 顺序添加对象和键值来创建一个字典,注意结尾是nil -(id)initWithObjectsAndKeys::obj1,key1,obj2,key2,......nil 初始化一个新分配的字典,顺序添加对象和值,结尾是nil -(unsigned int)count 返回字典中的记录数 -(NSEnumerator*)keyNSEnumerator 返回字典中的所有键到一个 NSEnumerator 对象 -(NSArray*)keysSortedByValueUsingSelector:(SEL)selector 将字典中所有键按照selector 指定的方法进行排序,并将结果返回 -(NSEnumerator*)objectEnumerator 返回字典中所有的值到一个 NSEnumetator 类型对象 -(id)objectForKey:key 返回指定key 值的对象 NSMutableDictionary 常用方法总结 +(id)dictionaryWithCapacity:size 创建一个size大小的可变字典 -(id)initWithCapacity:size 初始化一个size 大小的可变字典

How to swap `NSMutableDictionary` key and values in place?

独自空忆成欢 提交于 2019-12-10 12:55:43
问题 I have a NSMutableDictionary and I want to swap values & keys. i.e, after swapping values becomes keys and its corresponding keys with become values All keys and values are unique. Looking for an in place solution because size is very big . Also, the keys and values are NSString objects 回答1: NSMutableDictionary *d = [NSMutableDictionary dictionaryWithDictionary:@{ @"key1" : @"value1", @"key2" : @"value2"}]; for (NSString *key in [d allKeys]) { d[d[key]] = key; [d removeObjectForKey:key]; }