nsdictionary

Store NSDictionary in keychain

元气小坏坏 提交于 2019-11-29 21:47:39
It is possible to store a NSDictionary in the iPhone keychain, using KeychainItemWrapper (or without)? If it's not possible, have you another solution? Bret Deasy You must properly serialize the NSDictionary before storing it into the Keychain. Using: [dic description] [dic propertyList] you will end up with a NSDictionary collection of only NSString objects. If you want to maintain the data types of the objects, you can use NSPropertyListSerialization . KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"arbitraryId" accessGroup:nil] NSString *error; //The

How to pass a NSDictionary with postNotificationName:object:

余生颓废 提交于 2019-11-29 21:19:00
I am trying to pass an NSDictionary form a UIView to a UIViewController using NSNotificationCenter. The dictionary works fine at the time the notification is posted, but in the receiving method I am unable to access any of the objects in the dictionary. Here is how I am creating the dictionary and posting the notification... itemDetails = [[NSDictionary alloc] initWithObjectsAndKeys:@"Topic 1", @"HelpTopic", nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"HotSpotTouched" object:itemDetails]; In the UIViewController I am setting the observer... [[NSNotificationCenter

Get all keys of an NSDictionary as an NSArray

做~自己de王妃 提交于 2019-11-29 21:10:13
Is it possible to get all the keys from a specific NSDictionary as a seperate NSArray ? Just use NSArray*keys=[dict allKeys]; In general, if you wonder if a specific class has a specific method, look up Apple's own documentation . In this case, see NSDictionary class reference. Go through all the methods. You'll discover many useful methods that way. Yes it's possible. Use allKeys method: NSDictionary *yourDictionary; NSArray * yourKeys yourKeys = [yourDictionary allKeys]; And if you want to get all keys and values , here's what you do: for (NSString *key in dictionary) { id value = dictionary

How to get the duration of an audio file in iOS?

人走茶凉 提交于 2019-11-29 19:36:26
NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filename error:nil] From the file attribute keys, you can get the date, size, etc. But how do you get the duration? In the 'File Attribute Keys' of the NSFileManager class reference you can see that there is no key to use that will return the duration of a song. All the information that the NSFileManager instance gets about a file is to do with the properties of the actual file itself within the operating system, such as its file-size. The NSFileManager doesn't actually interpret the file. In order to get the

How to restructure object of NSDictionaries

元气小坏坏 提交于 2019-11-29 18:16:21
In my debugger this is how my log statement is printing my messages object: self.messages = ( "<lean: 0x7fcf98665140, objectId: vglE1UJ5KI, localId: (null)> {\n messageBody = Jj;\n recipientId = XvvxETqjph;\n senderId = XvvxETqjph;\n timestamp = \"1424991590106.210938\";\n}", "<lean: 0x7fcf98667940, objectId: rgBFYBMKlU, localId: (null)> {\n messageBody = \"test 3 from ian\";\n recipientId = XvvxETqjph;\n senderId = Hoy7UjLzOh;\n timestamp = \"1424631667110.638184\";\n}", "<lean: 0x7fcf98667f30, objectId: hB5uhwsYsu, localId: (null)> {\n messageBody = \"test 2 from user1\";\n recipientId =

Retrieve NSDictionary from NSArray where dictionary key has value X

谁都会走 提交于 2019-11-29 18:12:46
问题 I have an NSArray with NSDictionaries . One of the dictionaries keys in one of the arrays contains a value. I want to retrieve the NSDictionary with that value. My array: Array: ( { DisplayName = "level"; InternalName = "Number 2"; NumberValue = 1; }, { DisplayName = "PurchaseAmount"; InternalName = "Number 1"; NumberValue = 3500; } ) So, I would like to get the dictionary which contains DisplayName set to PurchaseAmount (case insensitive). How can I accomplish that? 回答1: LIKE[cd] will also

OC 学习笔记6 NSDictionary

你说的曾经没有我的故事 提交于 2019-11-29 16:37:07
OC 学习笔记6 NSDictionary 文章目录 OC 学习笔记6 NSDictionary 字典对象 字典的创建 1、创建只有单个键值对的字典 2、创建只有多个键值对的字典 判断键值对数目 运用count函数 查找/得到值(value),键(key) 1、通过单个键,查找单个值。 2、查找所有值(键)。 3、通过多个键,查找多个值。 字典对象 字典(dictionary)是一些元素的集合。每个元素有一个称作key 的域,不同元素的key 各不相同。有关字典的操作有:插入具有给定关键字值的元素、在字典中寻找具有给定关键字值的元素、删除具有给定关键字值的元素。 --百度百科 字典对象就是形如:*dict = @{@“Alice”: @“2341”, @“Beth”: @“9102”,@“Cecil”?“3258”}; 这样的元素集合。 它与数组不同之处是: 数组元素的存储是连续的; 而字典的存储是分散的。 字典的创建 1、创建只有单个键值对的字典 NSDictionary * a = [ NSDictionary dictionaryWithObject : @ "value1" forKey : @ "key1" ] ; NSLog ( @ "%@" , a ) ; 输出结果为: key1 = value1 2、创建只有多个键值对的字典 //通过数组对象来创建字典

NSManagedObject as NSDictionary key?

天涯浪子 提交于 2019-11-29 16:35:55
问题 In my app, I have a NSDictionary whose keys should be instances of a subclass of NSManagedObject . The problem, however, is that NSManagedObject does not implement the NSCopying protocol which means that no Core Data objects / instances of NSManagedObject can be used as dictionary keys even though the -[hash] method works fine for them. Was should I do? 回答1: There are four options: Use a different object as the dictionary key instead, and lookup from that. [object objectID] or +[NSValue

Updates to NSDictionary attribute in CoreData not saving

我是研究僧i 提交于 2019-11-29 16:10:15
问题 I have created an Entity in CoreData that includes a Transformable attribute type implemented as an NSDictionary. The NSDictionary attribute only contains values of a custom class. The properties of the custom class are all of type NSString. The custom class complies with NSCoding implementing: -(void)encodeWithCoder:(NSCoder*)coder; -(id)initWithCoder:(NSCoder *)coder When saving the Entity for the first time all attributes including the Transformable (NSDictionary) type are properly saved

parsing NSJSONReadingAllowFragments

佐手、 提交于 2019-11-29 14:50:32
I am receiving some json data in my app: NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonResponse options:NSJSONReadingAllowFragments error:nil]; NSLog(@"json :%@", json); which logs: json :{ "email" : "/apex/emailAttachment?documentId=00PZ0000000zAgSMAU&recipientId=003Z000000XzHmJIAV&relatedObjectId=a09Z00000036kc8IAA&subject=Pricing+Comparison" } This is exactly what I want. However, when I go to read the value of the email by doing [json objectForKey:@"email"] I receive an invalid argument exception: Terminating app due to uncaught exception