nsdictionary

How to convert NSManagedObject to NSDictionary

橙三吉。 提交于 2019-11-30 09:22:48
I am trying to convert NSManagedObject to NSDictionary this is what I tried: var keys:NSArray = order?.entity.attributesByName.keys var dict:NSDictionary = order?.dictionaryWithValuesForKeys(keys) But I get error: LazyForwardCollection<MapCollectionView<Dictionary<NSObject, AnyObject>, NSObject>>? is not convertible to NSArray. What am I doing wrong here? The keys property of a dictionary returns a LazyForwardCollection which has to be converted to a real array. Another problem is that order is apparently an optional, so it needs to be unwrapped, e.g. with optional binding. if let theOrder =

Reading plist file

谁说我不能喝 提交于 2019-11-30 09:08:56
I created plist with big base of different animals in it (keys) and added this plist in my project. Type of every animal is NSDictionary. In every dictionary there are 5 more keys - characteristics of these animals (). I would like to go through every animal and if I match a certain characteristics of this animal, I put this animal in another array. So, I tried to make a code: NSArray *newArray = [[NSArray alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"animals" ofType:@"plist"]]; for (int i = 0;[newArray objectAtIndex:i];i++) { if ([[newArray objectAtIndex:i]objectForKey

NSDictionary with NSNumber to NSString mapping is non-property-list object

痴心易碎 提交于 2019-11-30 09:07:24
问题 Following code: [[NSUserDefaults standardUserDefaults] setObject:photoIdToPath forKey:@"photo_id_to_path"]; gives me the following error: Attempt to set a non-property-list object { 417675729 = "/Users/k06a/Library/Application Support/iPhone Simulator/7.1/Applications/21163736-DF6F-4E79-8196-6A966C81ED1B/Documents/417675729"; } as an NSUserDefaults value for key photo_id_to_path Here is photoIdToPath dictionary content analysis from Xcode debug console: (lldb) po photoIdToPath { 417675729 = "

Objective-C

爱⌒轻易说出口 提交于 2019-11-30 08:18:01
Objective-C - Foundation框架初探 Foundation之于Objective-C就好比Java中SDK类库之于Java。 这个框架提供了基本的Objective-C的类,最重要的根类,NSObject,它定义了基本的对象行为。 框架包括了各种基本数据类型、集合,操作系统服务的对象的类。Foundation同样包含了几种设计模式 和机制,以遍设计出更健壮和高效的Objective-C程序。 一:基本的Protocols (类似于Java中的接口。明显的区别是,Protocols中允许可选实现方法。 我下面写的“采纳”类似于Java中的实现。 (1)NSObject ,值得注意的是它的名字跟NSObject类同名。 采纳了这个协议的类,就可以被查询它们的类和父类,可以跟其他对象比较。 (2)NSCoding,采纳了这个协议的类可以被编码和解码。 (3)NSCoping,这个协议只定义了一个方法,copyWithZone:,如果一个类支持对象拷贝那么就需要采纳这个协议。 二:基本的类 (1)NSObject ,NSObject类是Objective-C类继承体系中的根类。 NSObject类采纳了NSObject协议。 (2)NSNumber ,它是用于处理基本数据类型的工具类,是NSValue的子类。 它为标量提供了面向对象的封装和指针。值得注意的事

NSDictionary: method only defined for abstract class. My app crashed

此生再无相见时 提交于 2019-11-30 08:05:55
My app crashed after I called addImageToQueue. I added initWithObjects: forKeys: count: but it doesn't helped me. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSDictionary initWithObjects:forKeys:count:]: method only defined for abstract class. Define -[DictionaryWithTag initWithObjects:forKeys:count:]!' my code - (void)addImageToQueue:(NSDictionary *)dict { DictionaryWithTag *dictTag = [DictionaryWithTag dictionaryWithDictionary:dict]; } @interface DictionaryWithTag : NSDictionary @property (nonatomic, assign) int tag; - (id)initWithObjects:(id *

How to create an NSDictionary with multiple keys?

≡放荡痞女 提交于 2019-11-30 07:34:13
I am not sure if what I am going to ask is actually an NSDictionary with multiple keys but ok. What I want to do is create an NSDictionary with keys and values for my data and then convert it to JSON format. The JSON format would look exactly like this : { "eventData": { "eventDate": "Jun 13, 2012 12:00:00 AM", "eventLocation": { "latitude": 43.93838383, "longitude": -3.46 }, "text": "hjhj", "imageData": "raw data", "imageFormat": "JPEG", "expirationTime": 1339538400000 }, "type": "ELDIARIOMONTANES", "title": "accIDENTE" } I ve only used NSDictionaries like this : NSArray *keys = [NSArray

UIPickerView with NSDictionary

Deadly 提交于 2019-11-30 07:12:32
I am a .NET programmer and new to Objective C. I am trying to make a UIPickerView which acts like a .NET dropdownlist. User sees the list of text and selects one and the selected value (which is the ID) is used in code. I have been browsing for almost half a day trying to figure this out. I could add a regular PickerView with list of strings, picker view with mulitple components and picker view with dependent components none of which seems to answer my query. Please help. You can use a NSDictionary as a data source for UIPickerView but if you have a custom NSObject that already contains the

sort NSDictionary values by key alphabetical order

こ雲淡風輕ζ 提交于 2019-11-30 06:30:49
问题 I can get an array of dictionary keys sorted by values, but how to I get an array of values sorted by dictionary keys? I've been looking everywhere with no luck. Any help appreciated. 回答1: This might work: NSArray * sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)]; NSArray * objects = [dict objectsForKeys: sortedKeys notFoundMarker: [NSNull null]]; or in Swift let objects = dict.keys.sorted().flatMap{ dict[$0] } or let objects = dict.sorted{ $0.0 < $1

iOS: Why can't I set nil to NSDictionary value?

谁说胖子不能爱 提交于 2019-11-30 05:36:00
This might be very basic question but I was wondering why can't I assign nil as NSDictionary value? I have following statement many places in my code. If [q objectForKey:@"text"] is nil then App is crashing. NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2]; [dict setObject:[q objectForKey:@"text"] forKey:@"text"]; I have to check everywhere for the nil before assigning it to dictionary. Is this the only correct way of doing? Am I missing something obvious? if([q objectForKey:@"text"] != nil) [dict setObject:[q objectForKey:@"text"] forKey:@"text"]; else [dict

Retrieving values from json using objective-c

喜你入骨 提交于 2019-11-30 05:27:17
I am currently trying to work with json and objective-c however having a bit of difficulty. The following is the json that is being returned { sethostname = ( { msgs = "Updating Apache configuration\nUpdating cPanel license...Done. Update succeeded.\nBuilding global cache for cpanel...Done"; status = 1; statusmsg = "Hostname Changed to: a.host.name.com"; warns = ( ); }); } I am able to check that the response is coming back and the key is sethostname however no matter what I try I cannot get for example the value of status or statusmsg. Can anyone point me in the right location. The following