nsdictionary

What does this Objective-C dictionary code do?

不问归期 提交于 2019-12-02 17:54:16
问题 .h @property (nonatomic, strong) NSMutableDictionary * products; //not synthesized in .m .m - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSLog(@"Loaded list of products..."); _productsRequest = nil; NSArray * skProducts = response.products; for (SKProduct * skProduct in skProducts) { IAPProduct * product = _products[skProduct.productIdentifier]; product.skProduct = skProduct; product.availableForPurchase = YES; } for (NSString *

Create index for UITableView from an NSArray

元气小坏坏 提交于 2019-12-02 17:45:36
I've read that the best way of creating an index (the a-z at the side of a uitableview) is to set up an array of nsdictionaries, where each dictionary corresponds to a section, and a rowValue key contains an array of the rows. NSDictionary headerTitle => ‘A’ rowValues => {”Aardvark”, “Ape”, “Aquaman”} NSDictionary headerTitle => ‘B’ rowValues => {”Bat”, “Boot”, “Bubbles”} etc But how can this be created from an array of all the row titles - {”Aardvark”, “Ape”, “Aquaman”, ”Bat”, “Boot”, “Bubbles”, "Cat", "Cabbage" etc} ...? #pragma mark - #pragma mark View lifecycle - (void)viewDidLoad { [super

pulling unique values from an array of custom objects

早过忘川 提交于 2019-12-02 17:32:18
问题 i have an array list of custom objects. each object contains a value i need to pull out, claimNO, but is not a unique value, meaning say 5 objects may have the same claimNO. what i need to do is make an array that only has unique claimNO's. i need to display this in a picker and can't have any repeating claimNO. my object: @interface ClaimCenterClaim : NSObject { NSNumber *claimID; NSString *claimNO; NSNumber *coid; NSString *eventDates; } @property (nonatomic, retain) NSNumber *claimID;

Inserting nil objects into an NSDictionary

心不动则不痛 提交于 2019-12-02 17:10:46
If we have an API that requires only 2 out of an objects 5 properties and iPhone app doesn't require them to instantiate an object, when the object is used in the params NSDicitionary the app will crash. I was told NSDictionary will not let you assign nil values, as when it reaches nil it thinks its finished. Does objective-c have a way to spit out an objects non-nil properties into an NSDictionary? Example: [Drunk alloc] init]; drunk.started_drinking = [NSDate date]; drunk.stopped_drinking (we don't set this because he is still a drunk) drunk.fat = YES; drunk.dumb = YES; parameters:@{ @"auth

Appending NSDictionary to other NSDictionary

霸气de小男生 提交于 2019-12-02 16:55:01
I have one NSDictionary and it loads up UITableView . If a user scrolls more and more, I call API and pull new data. This data is again in the form of an NSDictionary . Is it possible to add the new NSDictionary to the existing one? MGA You looking for this guy: [NSMutableDictionary addEntriesFromDictionary:] Make sure your UITableView dictionary is an NSMutableDictionary ! Check it here Use NSMutableDictionary addEntriesFromDictionary to add the two dictionaries to a new mutable dictionary. You can then create an NSDictionary from the mutable one, but it's not usually necessary to have a

Beautify NSLog of NSArray & NSDictionary

…衆ロ難τιáo~ 提交于 2019-12-02 16:35:06
I'm dealing with deeply nested NSArray's and NSDictionary's and it's very time consuming to say the least. [data objectatindex:0] valueForKey:@"blah"] etc etc Does anyone know of a nice iOS category to recursively log the structure, highlight the type and show the values? Might be asking a bit much but you never know :) Maybe like this? for (id key in dictionary) { NSLog(@"key: %@, value: %@ \n", key, [dictionary objectForKey:key]); } but i can't think of any nice way of getting the output beautiful except copy & paste it into a jsonFormatter (for example) EDIT : @Andrey Starodubtsev has the

Trying to encrypt an NSDictionary when writing to file

主宰稳场 提交于 2019-12-02 15:54:55
I'm currently saving an NSDictionary to file on the iOS device. However, NSDictionary files are readable XML. I don't want people to be able to get in and read the contents so I need to be able to encrypt the file on writing and decrypt when loading it back again. I'm currently saving the file like this: NSFileManager* fileManager = [NSFileManager defaultManager]; if (!fileManager) { NSLog(@"Failed to get file manager to save."); return; } NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* documentsDirectory = [paths objectAtIndex:0];

post parameter to sever using dictionary swift

烂漫一生 提交于 2019-12-02 15:11:59
问题 I am trying to send data to the server using a dictionary but unfortunately the data is not saving to the database (fields were found to be blank) and I am getting the below response: Optional(["status": true, "msg": successfull]) And also tried to show UIActivityIndicator to user until he got a response but couldn't find a way. Code attempted: let dict = [ "key_one": self.tf1.text!,"key_two":self.tf2.text!] do { let jsonData = try NSJSONSerialization.dataWithJSONObject(dict, options:

Instantiating Custom Class from NSDictionary

荒凉一梦 提交于 2019-12-02 14:56:37
I have a feeling that this is stupid question, but I'll ask anyway... I have a collection of NSDictionary objects whose key/value pairs correspond to a custom class I've created, call it MyClass . Is there an easy or "best practice" method for me to basically do something like MyClass * instance = [ map NSDictionary properties to MyClass ]; ? I have a feeling I need to do something with NSCoding or NSKeyedUnarchiver , but rather than stumble through it on my own, I figure someone out there might be able to point me in the right direction. The -setValuesForKeysWithDictionary: method, along with

Can't extract needed information from NSDictionary

余生颓废 提交于 2019-12-02 14:46:28
问题 I parse a XML file, and after parsing get a NSDictionary object (XMLDictionary named). I'm parsing this: <result><node><id>27</id><name>Name 1</name><type>0</type><price>0</price><img>/upload/iblock/1a1/1a138b2d4da6e42398beeb21acc8e84f.png</img></node><node><id>28</id><name>Name 2</name><type>0</type><price>0</price><img>/upload/iblock/b72/b724d1550f93987a73b04974b5f7390e.png</img></node></result> After that i'm trying this (titleArr - NSArray): _titleArr = [[[[_xmlDictionary objectForKey:@