How to get the array of all keys from the dictionary in the existing order? [duplicate] - iphone

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to sequentialy access a dictionary??
I have a dictionary , I want to reitrive all keys in an array with the same order which exist inside the dictionary . The documentation on "allKeys" method of NSDictionary says the order of returned objects in array is not defined . What can be done to get the keys in the same order as that of the dictionary .
Thanks a lot in advance !!

So the question you were pointed to summarises the issue nicely, but the solutions offered could be a little bit too complex for your needs (if you didn't want / have the time to write a sub-class or your own data structure).
The quick and dirty alternative is simple to have an array that contains all the keys you want to access in the order you want to access them in. You can then simply match this array back to your dictionary to pull out values in the correct order.

Related

How to store more than 2 members information?

I have created a registration form using drag and drop and storing details in an array . But the problem is it is storing only one member details . if i fill another details the first member details are replaced by second ones . how i can get solution to this issue .
Create an array of objects and use a looping statement to traverse through the array and with the help of this keyword store your information in different objects. This way your member details will not be lost.

REDIS : See everything that is under the "field"

It's quite complicated to explain.
What I want is to have a command that takes as a parameter the field and displays all keys and values ​​in this field.
I go around the REDIS documentation and I found HGETALL and HMGET, but these two commands do not meet my need.
HGETALL asks in parameter for the key and show all the fields with their value.
Example here : http://redis.io/commands/hgetall
HMGET takes in parameter the key and the field which are attached to it and show their values. Example here: http://redis.io/commands/hmget
There is also HKEYS but there either that does not give what I want.
If there is no very precise command, I shall like knowing how I could code so that that gives something close to what I wish to make and if it is possible.
Thank you in advance for your answers.
If I understood it well, you have several Hash, each with its own key. Then you have in these hashes a field, for example the field "name". Now you want to ask something like "tell me in which keys I have stored the name attribute and what is the value"
If that's your case, there are some options to do that in redis, but it wouldn't be the best way of storing the information.
A possible way of doing this is using a common pattern for all the keys in which you will store the field name. For example "record:a", "record:b"... Then you could issue a KEYS command like KEYS record: and you would get all the keys for your hashes. (note SCAN is more efficient)
Next you would need to issue several commands like hget key, name. You can use a MULTI so all the commands are executed at the same time.
With that process, you would get all the keys in the 1st step and all the values in the second. But I don't think this is optimal.
If I knew your use case, maybe I could help more
I think that you are understand but i'm not english and even if I translate on web-site (google-translate) I haven't all understand your answer. Sorry.
I have try with KEYS. I have the list of my fields used on my hashes. I have had an idea, It's do bla=KEYS *, do a blas.each do |bla| and in the each ... do, do #bla=hget(...,'bla'). Or something like this. But it's not possible, I haven't the key.
Infact I am trying to replace sqlite3 by Redis in Ruby on Rails scaffold is. it is in the controller where the index is displayed all values ​​in the hashes.
To be more clear :
def index
#counters = Counter.all
end
I want replace this code by something like that :
def index
#counters = REDIS.hget
end

CoreData fetch entities with same values

I have a CoreData entity called Item with two values (well, two values relevant to this question).
Item
---------------
id - NSString
name - NSString
Every item has a unique ID and SHOULD have a unique name.
(BTW, the id is not used for CoreData it is used for communicating with the server).
There are a couple of items which appear to have duplicate names and I'm trying to find a query that returns all items that have an item in the table with a duplicate name.
Is this possible?
If so, can someone provide an NSPredicate (or method) to do this.
I do not think that it is possible to fetch exactly the items with duplicate names with a Core Data fetch request. (I think there was a similar question some time ago here on SO, but I cannot find it right now.)
You could fetch all items sorted by the name attribute. Then the duplicates can be found with a single loop over the result array.

Get NSMutableDictionary Keys as Strings? [duplicate]

This question already has answers here:
NSDictionary dictionaryWithContentsOfFile doesnt load the data in order
(3 answers)
Closed 8 years ago.
I have an NSMutableDictionary with 10 objects each with a key of course, the keys are all words and this is in a plist.
So I have entered these words into the plist in a specific order:
e.g.
hello
goodbye
please
thankyou
How can I get these keys as an array of strings? I have tried allKeys but for some reason it puts them all out of order and words with spaces in are given quotation marks (I've seen this from logging the array).
Any help much appreciated.
NSMutableDictionary doesn't keep data in any specific order. Instead, you should use an NSArray. That way you will have the words in your desired order and use them to access the dictionary to retrieve the dictionary's data.

iphone version of Android contacts attributes?

I'm looking for a way to query contacts in my iPhone app based on a few things. First I only want contacts that have a phonenumber. Second, id like to sort the contacts in order of the number of times contacted.
Android provides attributes that makes this possible and easy to do.
I can't really say that I know the answer, but I believe I know where to find the answer:
http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html#//apple_ref/doc/uid/TP40007744-CH1-SW1
Here are some quotes from that document that seems relevant:
There are two ways to find a person record in the Address Book database: by name, using the function ABAddressBookCopyPeopleWithName, and by record identifier, using the function ABAddressBookGetPersonWithRecordID. To accomplish other kinds of searches, use the function ABAddressBookCopyArrayOfAllPeople and then filter the results using the NSArray method filteredArrayUsingPredicate:.
To sort an array of people, use the function CFArraySortValues with the function ABPersonComparePeopleByName as the comparator and a context of the type ABPersonSortOrdering. The user’s desired sort order, as returned by ABPersonGetSortOrdering, is generally the preferred context.
Those quotes were both found on this page. I hope it helps.