Tip:
Highlight text to annotate it
X
time and time again it will work with the c style arrays will work with an ***
a raisin and asked me to below raised and they're great for working with
collections of objects as long as you're happy by accessing each of those
elements using that
zero-based array index
what if you're not
well we also have another object we can use is called a dictionary
and the idea of a dictionary in objective c is like the idea of
addiction it on your book shelf
the whole point of a dictionary is that you have a word
and a description
the words are the key to the right place in the dictionary but you're using the
words to look of the description
that doesn't mean
or actually writing a dictionary a
set of descriptions and terms in our program although we cud
what you'll find is that addiction l_j_ could be commonly used for things like
state or country look-up tables where we have common abbreviations
and we can use those as the keen to the actual entry in this case daisy goes to
arizona c_a_a_ to california and so on
you could use them as a simple lookups for
product lists because it's up to you what that key heads
now usually eds a string
but it could be just say a number
and well gee you think of the dictionary entry itself being another string or
could be any object
so we did have the word start date look up and and i think for example
but we are imposing our own structure on
how these individual entries are looks up
so let me show you how to write one
in another simple
project here just a command-line foundation told
i'm going to type in an s diem glenn is dictionary
if you occasionally try to do some of the code sense and you don't see
anything appear do make sure you've done a recent build because sometimes xcode
who likes to have a building done before it'll present you with all the code
sense so make an honest dictionary
it is of course a prototype i'll call it states
and what i'm going to do is i'm going to use
the methods of m s dictionary called dictionary with objects and keys
this will give me
and or to released tennis dictionary
if i wanted more money or comptroller
i'd say an *** dictionary alag
inlet with objects in keys
but this will do just fine
i noticed the phrasing here dictionary with objects and keys
unlike an array we do have to provide two pieces of information for teach slot
and it's also telling us what order they need to be in which is object then ke
not ke then object
the object would be as owner manana stringer comment the key would be an
easy
let me do a couple more of these amid a split is on another line just to make it
a little bit more readable
i'll just add a few right now
and then like working with an array
indicate the radon
by the word nail
close the square brackets and we're done
well the whole reason for creating a dictionary is that we are going to
access it at some point the futures alot imagine that
a little later on in our program
we have a state abbreviation and we need to use it to look up the rights slotkin
the dictionary
soldiers create
and in a string object alder st i don't have to do it this way i could have just
use the literal but this would be fun
i'll call it some state and said it equal to exiting
and then we'll do an annus log message
have to placeholders
percent site and sign
is for percent sign out sign
first place holder will be filled by the some states abbreviation
and the second one or we're going to do
is use the state's dictionary
and they use the method called object for keith
and here's where passivity
which i have some state and santana strength and that's fine
save them
as we see here age the as for arizona
yeah no particular surprise here
feed n_c_a_a_ c_a_a_ has for california
the thing is we don't have to know
what position and these are in in the dictionary
but even though
the few entries that i put in i did in alphabetical order you don't have to do
that
dictionaries quite capable of looking up these different values you don't have to
impose
your own thought structure on them
it's fine if it was the other way around or even all mixed up
adjust liked working with and answering
the m_s_ dictionary is
immutable it's unchangeable after it has been created
you cannot add a new entry to it
but also
just like the n_ s_ or a new minority going with this
there is another version of it colby anis musical dictionary
and we just add the word mutual in here
bennis musical diction inherits from anna's picture which means it has all
the same methods
it just has a few more
as the example
the few more includes they method
called
set object
co launched fourteen
this is how we
a new object into the m_s_ mutual diction
so in this case i'll just say this was florida forty
and not surprisingly if i just feel n_f_l_ for it
and run that will get as well as for florida
now when you start working
with addiction and you'll find a quick comment and it wasn't quite large ones
and sometimes it can be useful
q automatically be able to loop through all of them without knowing exactly how
many there are unlock early
we can do that to something called fast enumeration of supported an objective c
camel going for that next