nsdictionary

iPhone - Writing a dictionary to file : handling errors

家住魔仙堡 提交于 2019-12-10 22:22:04
问题 When saving a NSDictionary to file using : - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag YES or NO can be returned. There are some methods for writing files that accept a NSError parameter. In the case of the NSDictionary, such a method doesn't exist. So if the writeToFile method returns NO, how may I know what happened ? 回答1: Look at the docs for writeToFile:atomically: to see which data types can be in a dictionary when you use this method. If you include an object not among

iOS NSDictionary saved to NSUserDefaults not saving values

谁说胖子不能爱 提交于 2019-12-10 20:47:47
问题 I am trying to save a NSDictionary with array values to NSUserDefaults but am having some strange trouble. My NSDictionary has NSStrings for keys and each value is a NSArray of NSNumbers . When I print the dictionary out, everything is fine. I write this dictionary to NSUserDefaults and if I read it back out right away, everything seams fine. Using this everything seams just fine: [[NSUserDefaults standardUserDefaults] setObject:self.selectedOptionPositions forKey:PREF_OPTIONS_KEY]; [

Save an UIImagePicker Video

自古美人都是妖i 提交于 2019-12-10 20:38:20
问题 I have searched and searched but can not find a basic UIImagepicker video save code. I have everything set up and just have a blank void. - (void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *) info{ } I know it has something to do with the dictionary, but after that I'm lost, any help? 回答1: Try this code for save the video on photo album. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:

NSDictionary description not returning utf8 characters?

北战南征 提交于 2019-12-10 19:44:32
问题 I have an NSDictionary with utf8 strings as objects. Printing the objects prints the special characters as they should. But utf8 characters do not get correctly printed out when I convert the dictionary to a string with the description method. NSDictionary *test = [NSDictionary dictionaryWithObject:@"Céline Dion" forKey:@"bla"]; NSLog(@"%@",[test objectForKey:@"bla"]); // prints fine NSLog(@"%@",test); // does not print fine, é is replaced by \U00e NSLog(@"%@",[test description]); // also

Foundation Objective-c: Dictionary with array; dict with dict

早过忘川 提交于 2019-12-10 18:44:22
问题 Suppose I have a NSDictionary with two sub collections of a NSArray and a NSDictionary: NSMutableDictionary *mkDict(void){ NSMutableDictionary *dict=[NSMutableDictionary dictionary]; NSMutableDictionary *sub=[NSMutableDictionary dictionary]; NSMutableArray *array= [NSMutableArray array]; [dict setObject:array forKey:@"array_key"]; [dict setObject:sub forKey:@"dict_key"]; return dict; } There are a multitude of ways to access a single element of the sub-collection, and I choose to time three

How to get key/value pair from NSDictionary?

蓝咒 提交于 2019-12-10 18:16:38
问题 I need little help with NSDictionary. How can I get 1 pair, lets say a value for "id" if I have dictionary NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers error:&error]; and it looks like this: Thanks for Your help. 回答1: The shortest way: NSNumber *number = allCourses[@"semacko"][@"id"]; 回答2: Try this: NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers

IOS 字典模型互转框架 MJExtension

点点圈 提交于 2019-12-10 16:58:59
详细轻参考: https://github.com/CoderMJLee/MJExtension 功能很牛掰 能做什么? MJExtension是一套 字典和模型之间互相转换 的超轻量级框架 MJExtension能完成的功能 字典(JSON) --> 模型(Model) 模型(Model) --> 字典(JSON) 字典数组(JSON Array) --> 模型数组(Model Array) 模型数组(Model Array) --> 字典数组(JSON Array) 详尽用法主要参考 main.m中的各个函数 以及 NSObject+MJKeyValue.h MJExtension和JSONModel、Mantle等框架的区别 转换速率: 最近一次测试表明: MJExtension > JSONModel > Mantle 各位开发者也可以自行测试 具体用法: JSONModel :要求所有模型类 必须 继承自JSONModel基类 Mantle :要求所有模型类 必须 继承自MTModel基类 MJExtension : 不需要 你的模型类继承任何特殊基类,毫无污染,毫无侵入性 如何使用MJExtension cocoapods导入: pod 'MJExtension' 手动导入: 将 MJExtensionExample/MJExtensionExample

Create NSObject from NSDictionary in objective-c

夙愿已清 提交于 2019-12-10 16:53:53
问题 I would like to assign each item from a dictionary into my object using a "for...in" loop I have a NSDictionary like that : {"user_id" : "1", "user_name" : "John"} And I have an NSObject with variable : NSString *user_id; NSString *user_name With a for in loop, I want to assign each item from my NSDictionary in my NSObject for (NSString *param in userDictionary) { } How I can do that ? Thanks, 回答1: Have a look at the NSObject class method: - (void)setValue:(id)value forKey:(NSString *)key;

NSPredicate not working with array of dictionaries

雨燕双飞 提交于 2019-12-10 16:46:45
问题 I have an NSPredication with format like this: @"Status CONTAINS[cd] shipped" I have an array of dictionary, here's an example: { { Category = "Category 4"; Comp = "Category 4"; Depth = 02; Grade = New; Length = 02; Location = "Thousand Oaks, CA"; Name = "3ply Mat"; Owner = "Owner 3"; PUP = 2; Status = Shipped; "Unit Number" = 20110507113852351; Width = 02; }, { Category = "Category 4"; Comp = "Category 4"; Depth = 02; Grade = New; Length = 02; Location = "Thousand Oaks, CA"; Name = "3ply Mat

OC中的NSDictionary(字典)

穿精又带淫゛_ 提交于 2019-12-10 16:19:14
字典的基本概念 OC中的字典( NSDictionary , NSMutableDictionary )是由键-值对组成的数据集合.正如,我们在字典里查找单词的定义一样. 通过 key (键),查找的对应的 value (值),key通常是字符串对象,也可以是其他任意类型对象.在一个字典对象中, key的值必须是唯一的 . 此外,字典对象的键和值不可以为空(nil),如果需要在字典中加入一个空值,可以加入NSNull对象 字典中存储方式是无序的,因为字典是没有下标的!!! 字典中存储方式是无序的,因为字典是没有下标的!!! 字典中存储方式是无序的,因为字典是没有下标的!!! NSDictionary(字典) 字典的初始化 key不要重复,重复了只识别第一个 int main(int argc, const char * argv[]) { @autoreleasepool { //不可变字典 //只有一个键值对的字典初始化 //将整数1转化成NSNumber类型,用a存放 NSNumber *a = [NSNumber numberWithInt:1]; //定义一个只有一个键值对的字典b,value值是"xiaoming", key值是a(其实就是1) NSDictionary *b = [NSDictionary dictionaryWithObject:@"xiaoming"