NSDictionary to NSData and NSData to NSDictionary in Swift

You can use NSKeyedArchiver and NSKeyedUnarchiver Example for swift 2.0+ var dictionaryExample : [String:AnyObject] = [“user”:”UserName”, “pass”:”password”, “token”:”0123456789″, “image”:0] let dataExample : NSData = NSKeyedArchiver.archivedDataWithRootObject(dictionaryExample) let dictionary:NSDictionary? = NSKeyedUnarchiver.unarchiveObjectWithData(dataExample)! as? NSDictionary Swift3.0 let dataExample: Data = NSKeyedArchiver.archivedData(withRootObject: dictionaryExample) let dictionary: Dictionary? = NSKeyedUnarchiver.unarchiveObject(with: dataExample) as! [String : Any] Screenshot of playground

Sorting NSArray of dictionaries by value of a key in the dictionaries

I think this will do it: brandDescriptor = [[NSSortDescriptor alloc] initWithKey:@”brand” ascending:YES]; sortDescriptors = [NSArray arrayWithObject:brandDescriptor]; sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors]; I pulled the code from Sort Descriptor Programming Topics. Also, Key-Value Coding comes into play, in that sortedArrayUsingDescriptors: will send a valueForKey: to each element in myArray, and then use standard comparators to sort the … Read more

How can we store into an NSDictionary? What is the difference between NSDictionary and NSMutableDictionary?

The NSDictionary and NSMutableDictionary docs are probably your best bet. They even have some great examples on how to do various things, like… …create an NSDictionary NSArray *keys = [NSArray arrayWithObjects:@”key1″, @”key2″, nil]; NSArray *objects = [NSArray arrayWithObjects:@”value1″, @”value2″, nil]; NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; …iterate over it for (id key in dictionary) { … Read more

Best way to sort an NSArray of NSDictionary objects?

Use NSSortDescriptor like this.. NSSortDescriptor * descriptor = [[NSSortDescriptor alloc] initWithKey:@”interest” ascending:YES]; stories = [stories sortedArrayUsingDescriptors:@[descriptor]]; recent = [stories copy]; stories is the array you want to sort. recent is another mutable array which has sorted dictionary values. Change the @”interest” with the key value on which you have to sort. All the best

Check key exists in NSDictionary

I presume that [dataArray objectAtIndex:indexPathSet.row] is returning an NSDictionary, in which case you can simply check the result of valueForKey against nil. For example: if ([[dataArray objectAtIndex:indexPathSet.row] valueForKey:@”SetEntries”] != nil) { // The key existed… } else { // No joy… }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)