How to sort an array which contains Dictionaries?

If every element in the array is a dictionary containing a certain key, you can sort the array using a sort descriptor. For instance, if every element is a dictionary containing a key called “name”: NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@”name” ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:sortByName]; NSArray *sortedArray = [array sortedArrayUsingDescriptors:sortDescriptors];

How can I use an integer value as ‘key’ to set value in NSMutableDictionary?

As NSDictionarys are only designed to deal with objects, a simple way to do this is to wrap the integer and float in a NSNumber object. For example: NSMutableDictionary *testDictionary = [[NSMutableDictionary alloc] init]; [testDictionary setObject:[NSNumber numberWithFloat:1.23f] forKey:[NSNumber numberWithInt:1]]; NSLog(@”Test dictionary: %@”, testDictionary); [testDictionary release]; To extract the relevant value, simply use the appropriate intValue, … 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

Where’s the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary?

setValue:forKey: is part of the NSKeyValueCoding protocol, which among other things, lets you access object properties from the likes of Interface Builder. setValue:forKey: is implemented in classes other than NSDictionary. setObject:forKey: is NSMutableDictionary’s reason to exist. Its signature happens to be quite similar to setValue:forKey:, but is more generic (e.g. any key type). It’s somewhat … Read more

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