nsdictionary

displaying JSON data with the help of dictionaries and array

时光怂恿深爱的人放手 提交于 2019-12-02 13:59:26
I get the following error [__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x75a8e20 2013-04-20 08:56:14.90 MyApp[407:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x75a8e20' This is my first hands on working with JSON. I get the above mentioned error when I try to run the first piece of code where URL is a flickr url. When I use the photos as key it print the array and app abruptly quits. #define flickrPhotoURL [NSURL URLWithString: @"http://api

NSDictionary order does not match allKeys order

风格不统一 提交于 2019-12-02 13:32:06
I've created NSDictionary of sorted arrays by name organized by first letter (see results below). When I use the command allKeys for that same Dictionary, the order is not the same. I need the order the same because this NSDictionary is used in UITableview and should be alphabetical. - (NSDictionary*) dictionaryNames { NSDictionary *dictionary; NSMutableArray *objects = [[NSMutableArray alloc] init]; NSArray *letters = self.exhibitorFirstLetter; NSArray *names = self.exhibitorName; for (NSInteger i = 0; i < [self.exhibitorFirstLetter count]; i++) { [objects addObject:[[NSMutableArray alloc]

What does this Objective-C dictionary code do?

穿精又带淫゛_ 提交于 2019-12-02 12:27:09
.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 * invalidProductIdentifier in response.invalidProductIdentifiers) { IAPProduct * product = _products

How to Sort an Array of NSDictionary using DateTime key (Swift 4)?

妖精的绣舞 提交于 2019-12-02 10:50:29
I have an NSArray of NSDictionary let Array = ( { name = "Auni"; age = "24"; transactionTime = "01-02-2011 12:32:39" }, { name = "Atiqah"; age = "23"; transactionTime = "02-02-2013 10:32:41" }, { name = "Aida"; age = "22"; transactionTime = "04-02-2020 18:32:21"}) How do I sort this array by most recent transactionTime ? Using Swift4. Thank you. Edit: It's easier to have back-end people do it for you. You do not need to convert into Date object, dateStrings direct comparison will also work. array.sort { (dict1, dict2) -> Bool in /// Considering "transactionTime" key always exists. let

Could not cast value of type '__NSArrayM' to 'NSDictionary'

荒凉一梦 提交于 2019-12-02 10:38:56
I have a json.I am trying to parse that with that code.But its says Could not cast value of type '__NSArrayM' to 'NSDictionary' do { let dataDictionary: NSDictionary = try NSJSONSerialization.JSONObjectWithData(responseObject as! NSData, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary // <------ Error if let customerArray = dataDictionary.valueForKey("cart") as? NSArray { for js in customerArray { let nameArray = js.valueForKey("name") let idArray = js.valueForKey("id") } } } Thank you for your helps The root object in your data is an array, not a object (dictionary). You

post parameter to sever using dictionary swift

耗尽温柔 提交于 2019-12-02 10:28:09
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: .PrettyPrinted) // create post request let url = NSURL(string: "myAPIUrl.php?")! let request =

Unrecognized selector error when indexing into a dictionary of arrays

半世苍凉 提交于 2019-12-02 10:17:47
问题 I have a dictionary of arrays that is causing __NSCFDictionary objectAtIndex: errors. Can someone tell me why? The dictionary clearly has at least 1 array at the time of the error. NSError *error; responseString = [[NSString alloc] initWithData:self.responseData2 encoding:NSUTF8StringEncoding]; /* response string contains this: {"words": { "word": {"rowsreturned":0,"id":"-1","date":"","word":"","term":"","definition":"","updated_on":""} }, "status":"", "rowsreturned":"" } */ NSDictionary

Difference between literals and class methods for NSMutableArray and NSMutableDictionary [duplicate]

孤者浪人 提交于 2019-12-02 09:49:26
问题 This question already has an answer here : Is literal creation of an NSMutableDictionary less efficient than the class helper method? (1 answer) Closed 6 years ago . When I started with OSX/iOS I used NSMutableArray * a1 = [NSMutableArray arrayWithCapacity:123] ; NSMutableDictionary * d1 = [NSMutableDictionary dictionaryWithCapacity:123] ; Then I discovered the 'simpler' version NSMutableArray * a2 = [NSMutableArray array] ; NSMutableDictionary * d2 = [NSMutableDictionary dictionary] ; I have

Converting NSDictionary to XML [duplicate]

混江龙づ霸主 提交于 2019-12-02 09:33:45
This question already has an answer here: Converting NSDictionary to XML 3 answers I need to convert a dictionary to XML format for using with SOAP webservice in objective C . Let the dictionary be { password = testpassword; username = testusername; } and the converted result i need is : <password>testpassword</password> <username>testusername</username> i need a specific function to get output like this format for dynamic dictioanry . many libraries are available but i dont get output like this . thanks in advance .. Please use below code for converting NSDictionary to XML. +(NSString*

Add objects to NSMutable array with grouping

拜拜、爱过 提交于 2019-12-02 09:14:27
I want my NSArray sampleData to receive actual data from parse.com database assuming like this: self.sampleData = @[ @{ @"date": @"12/5/2014", @"group": @[ @{ @"text": @"post1", @"location": @"x,y" }, @{ @"text": @"post2", @"location": @"x,y" }, @{ @"text": @"post3", @"location": @"x,y" }, @{ @"text": @"post4", @"location": @"x,y" }, @{ @"text": @"post5", @"location": @"x,y" } ] }, @{ @"date": @"12/3/2014", @"group": @[ @{ @"text": @"post6", @"location": @"x,y" }, @{ @"text": @"post7", @"location": @"x,y" }, @{ @"text": @"post8", @"location": @"x,y" }, @{ @"text": @"post9", @"location": @"x,y"