nsdictionary

Convert a JSON NSData to NSDictionary

佐手、 提交于 2019-12-10 03:04:29
问题 I'm using an API service of a web service and it is written in their description that they send JSON data wich also matches in my opinion with the response I get from it. Here a part of it which I got from the NSURLConnection-Delegate (connection didReceiveData: (NSData *) data) and converted in a NSString using: NSLog(@"response: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); Here the snippet: {"scans": { "Engine1“: { "detected": false, "version": "1.3.0.4959",

How to get values from a dictionary in iOS

风流意气都作罢 提交于 2019-12-10 02:14:02
问题 I am new to iOS . I created a login page and everything works fine. I used JSON for checking username and password and got the response from server in a dictionary format. I want to extract the values from the dictionary and check them in my program. The response which I get from the server is: json: { error = 0; msg = ""; value = { user = false; }; }; First I want to check if the value with the key error is 0 or 1 . Then I want to check the value with the key user . I don't know how I should

iOS路由详解

醉酒当歌 提交于 2019-12-10 00:30:30
本文如题,路由详解,注定是一篇详细解释iOS路由原理及使用的文章,由于此时正在外地出差,无法详细一一写出,只能不定时的补充。 一、什么是iOS路由 路由一词来源于路由器,可以实现层级之间消息转发的功能。 二、实例 12345678 @implementation UIResponder (GXRouter)- (void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo{ [[self nextResponder] routerEventWithName:eventName us 大专栏 iOS路由详解erInfo:userInfo];}@end 这是UIResponder的分类的方法,由此,每个继承与UIResponder的类都可以调用这个方法。而执行此方法的却不用在当前对象中,避免了某些控件想要做一些操作却无法完成的情况,比如一个vc中的view,如果在view中要操作vc跳转,此时就没必要用view持有vc了,直接调用此路由,在vc中实现对应方法即可。方便至极。 三、一些猜想 1 - (void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo; 这个方法及其不稳定

How to convert NSDictionary to custom object

僤鯓⒐⒋嵵緔 提交于 2019-12-09 14:54:46
问题 I have a json object: @interface Order : NSObject @property (nonatomic, retain) NSString *OrderId; @property (nonatomic, retain) NSString *Title; @property (nonatomic, retain) NSString *Weight; - (NSMutableDictionary *)toNSDictionary; ... - (NSMutableDictionary *)toNSDictionary { NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setValue:self.OrderId forKey:@"OrderId"]; [dictionary setValue:self.Title forKey:@"Title"]; [dictionary setValue:self.Weight forKey:@

What is difference between NSDictionary vs Dictionary in Swift?

萝らか妹 提交于 2019-12-09 14:04:08
问题 I'm learning Swift, and I can see Dictionary in it. But there are lots of examples that are using NSDictionary with Swift. What's the difference between these two? I want to use an array with index in Swift like an array in PHP. Which one is better to use? 回答1: Dictionary is a native Swift struct. NSDictionary is a Cocoa class. They are bridged to one another (within the usual limits), as the docs explain very clearly and fully. It's exactly parallel to Array and NSArray. 回答2: In practice and

NSPredicate on NSDictionary

 ̄綄美尐妖づ 提交于 2019-12-09 05:26:54
问题 I'm trying to make sections in a table view based on the alphabet and sort my entries alphabetically under these sections. I have collected the first letter in every entry of bandsArray in bandsArrayIndex and I'm now trying to use NSPredicate to count how many of each letter there are. I'm doing this by following this guide. They are using an NSArray and I'm using an NSDictionary and can't seem to get it to work. Can anyone help me out? The application crashes when trying to show the view

Saving an NSDictionary of NSArrays of custom objects

空扰寡人 提交于 2019-12-09 04:30:31
I have a dictionary (it's mutable if that makes a difference) which contains nsarrays, which in turn contain (subclass of NSObject)s I have implemented initWithCoder and encodeWithCoder like this: -(id)initWithCoder:(NSCoder *)aDecoder { self = [super init]; self.Title = [aDecoder decodeObjectForKey:@"Title"]; self.SiteAPIURL = [aDecoder decodeObjectForKey:@"SiteAPIURL"]; self.ID = [aDecoder decodeObjectForKey:@"ID"]; return self; } -(void) encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:self.Title forKey:@"Title"]; [aCoder encodeObject:self.SiteAPIURL forKey:@"SiteAPIURL"]; [aCoder

NSDictionary allKeys order

被刻印的时光 ゝ 提交于 2019-12-08 22:29:08
问题 I need to display in a UITableView the content of a NSDictionary returned by an API, respecting the order of the keys. I'm using : - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *key = self.data.allKeys[indexPath.section]; NSArray *list = self.data[key]; id data = list[indexPath.row]; PSSearchCell *cell = [PSSearchCell newCellOrReuse:tableView]; cell.model = data; return cell; } but as I do self.data.allKeys , I'm loosing the

dictionaryWithContentsOfFile returning nil from my property list file

好久不见. 提交于 2019-12-08 17:22:50
问题 I'm learning how to use plist files for storing data in my iPhone app. I've been reading a bunch of the questions about plist and dictionaryWithContentsOfFile on this site, but can't see what I'm doing wrong. The following line returns nil ("The dictionary is null" to the console). NSLog(@"The dictionary is %@",[NSDictionary dictionaryWithContentsOfFile:@"myFile"]); The myFile.plist file is in the resources folder, and contains a few strings: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE

NSDictionary allKeys - does it always return the same order?

时光怂恿深爱的人放手 提交于 2019-12-08 16:55:21
问题 I'm fairly new to Objective-C and I was working with NSDictionaries today and came across the allKeys method. As I understand, it returns an NSArray containing the keys for the dictionary in a random order. However, is this order always the same? ie, if I call allKeys on the same dictionary 20 times in a row am I guaranteed to get the same order of results? Thanks, 回答1: If you call the method 20 times in a row on a dictionary that is not being mutated , it most likely will return the same