nsdictionary

Unwrapping Json Swift (found nil)

北城以北 提交于 2020-01-15 12:15:33
问题 i currently trying to decode Json in Xcode, but i not succed to get one of them. This is what i get : [ { "id": "1", "title": "bmw", "price": "500.00", "description": "330", "addedDate": "2015-05-18 00:00:00", "user_id": "1", "user_name": "CANOVAS", "user_zipCode": "32767", "category_id": "1", "category_label": "VEHICULES", "subcategory_id": "2", "subcategory_label": "Motos", "bdd": {} } "pictures": [ { "name": "http://cars.axlegeeks.com/sites/default/files/4315/media/images/2014_BMW_Z4

Complex NSDictionary. Taken objectsforkeys and sorting them as NSArray or separate variables?

巧了我就是萌 提交于 2020-01-15 04:32:04
问题 I have an NSDictionary that was converted from XML that is really confusing me. If you could take a look and let me know the best method of getting the objects for the key class_id, I would really appreciate it. { response= { "@status" = ok; rosters = { "@page" = 1; "@page_count" = 1; "@records_per_page" = 50; "@total_record_count" = 8; roster = ( { "@class_id" = 0001; "@role" = 0; "@user_id" = 12345; class= { "@active" = false; "@name" = NAME; } } { "@class_id" = 0002; "@role" = 0; "@user_id

nested NSDictionary from plist

混江龙づ霸主 提交于 2020-01-15 03:48:08
问题 I have a plist, with main NSDictionary, in which its keys are dates. For every date, I have a NSDictionary in which the keys are (let's say) categories. Every Category holds Keys and values. I would like to create 2 variables that each will hold the correct NSDictionary: NSDictionary *dates = ? NSDictionary *Categories = ? Below is my plist, please help to understand how this should be done. **Note: I do know how to assign the first dates dictionary from the plist... just stuck with the

geting error with Dictionary

蓝咒 提交于 2020-01-15 03:09:13
问题 let parameter : Dictionary<String,AnyObject> = ["action":"add-playlist-item","playlist_id":self.dictPlayList.objectForKey("ID")!,"kod_id":arrayOfID] error ["action": add-playlist-item, "playlist_id": 166, "kod_id": <_TtCs21_SwiftDeferredNSArray 0x7c615620>( 21, 18 ) ] _TtCs21_SwiftDeferredNSArray 0x7c615620 what does this error mean?? 回答1: Array is a value type and it's not an object, but a struct. So it doesn't conform to AnyObject protocol. Use Any instead of AnyObject. See more details

Access NSDictionary via dot notation?

随声附和 提交于 2020-01-14 07:57:09
问题 Is there a way via dot notation to access the values of keys in an NSDictionary like this? NSDictionary *returnVal = [NSDictionary dictionaryWithObjectsAndKeys:@"Saturn", @"name", @"Gas Giant", @"type", nil]; NSLog(@"VALUE: %@", [returnVal valueForKey:@"name"]); // This is how I am doing it now. 回答1: There is no dot syntax for NSDictionary , but should consider using objectForKey: instead of valueForKey: Difference between objectForKey and valueForKey? 回答2: Not really, no. The dot notation is

Filter NSArray with NSDictionary (nested level of object) using NSPredicate ANY and IN?

北慕城南 提交于 2020-01-14 06:09:17
问题 I have one main array named originalListArray with multiple objects.Here is the example of object. Example.json I want to find that number of objects from the originalListArray , who have amenity_id matched with my filter data. I have do this, create one predicate usign ANY not self becuase NSArray with NSDictionary and in that Dictionary object may have NSArray data. This is working fine. NSPredicate *predicate=[NSPredicate predicateWithFormat:@"ANY amenities.amenity_id =='1')"]; This is not

Parse NSDictionary to a string with custom separators

泪湿孤枕 提交于 2020-01-12 18:48:22
问题 I have an NSMutableDictionary with some values in it, and I need to join the keys and values into a string, so > name = Fred > password = cakeismyfavoritefood > email = myemailaddress@is.short becomes name=Fred&password=cakeismyfavoritefood&email=myemailaddress@is.short How can I do this? Is there a way to join NSDictionaries into strings? 回答1: You can easily do that enumerating dictionary keys and objects: NSMutableString *resultString = [NSMutableString string]; for (NSString* key in

策略模式vs工厂模式的区别

帅比萌擦擦* 提交于 2020-01-12 16:00:26
定义: 工厂模式的思想主要为:多个类似的子类继承同一个父类,对其父类中的变量进行操作;工厂类负责判断、控制哪个子类被执行,而工厂类调用子类完成后,返回的结果是该子类的父类,该父类中的变量已经被操作过了,访问该父类,得到我们想要的结果 策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换。策略模式让算法独立于使用它的客户而独立变化。 1. 相似: 在模式结构上,两者很相似; 2.差别: 用途不一样 工厂是创建型模式,它的作用就是创建对象; 策略是行为型模式,它的作用是让一个对象在许多行为中选择一种行为; 关注点不一样 一个关注对象创建 一个关注行为的封装 解决不同的问题 工厂模式是创建型的设计模式,它接受指令,创建出符合要求的实例;它主要解决的是资源的统一分发,将对象的创建完全独立出来,让对象的创建和具体的使用客户无关。主要应用在多数据库选择,类库文件加载等。 策略模式是为了解决的是策略的切换与扩展,更简洁的说是定义策略族,分别封装起来,让他们之间可以相互替换,策略模式让策略的变化独立于使用策略的客户。 工厂相当于黑盒子,策略相当于白盒子; 策略模式例子 例1、 (1)策略模式的核心就是对算法变化的封装。 定义一个通用算法协议,让每个算法遵守其规则。 @protocol LHPlayerProtocol <NSObject> /** * Player开启视频

Filter array of dictionaries by NSString

做~自己de王妃 提交于 2020-01-12 10:28:54
问题 while implementing search functionality I need to filter array of dictionaries. I am using auto complete textfield method for search bar and am storing it into string. I can able to parse the array,But facing with below json [{"CertProfID":"4","Name":"Dodge","Location":"loc4","City":"city4","State":"state4","Zip":"zip5","Website":"http:\/\/cnn.com","Phone":"phone4","Email":"email4"}, {"CertProfID":"5","Name":"cat","Location":"loc5","City":"city5","State":"State5","Zip":"zip5","Website":"web5"

OC中NSDictionary(字典)、NSMutableDictionary(可变字典)、NSSet(集合)、NSMutableSet(可变集合)得常用方法

a 夏天 提交于 2020-01-11 21:05:04
字典用于保存具有映射关系数据的集合 一个key—value对认为是一个条目(entry),字典是存储key—value对的容器 与数组不同,字典靠key存取元素 key不能重复,value必须是对象 键值对在字典中是无序存储的 字典分:不可变字典(NSDictionary)和可变字典(NSMutableDictionary) 不可变字典一旦创建,键值对就不可更改,不可添加,不可删除,仅能读取key或者value 常用方法有: 1、创建字典对象 2、获取所有key值,获取所有value值 3、通过key值查询value 1、常见字典的常用方法 在创建字典对象时需要赋值键值对,但是顺序为:值,键,(值在前键在后的形式) NSDictionary *dic1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"Duke",@"name",@33,@"age",@"男",@"gender", nil]; NSLog(@"%@",dic1); NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"Duke",@"name",@33,@"age",@"男",@"gender", nil]; NSLog(@"%@",dic2); NSArray *keys = @[@