Wednesday, 24 September 2014

Collection logic


how logic here...

each quiz question, there selection of answers, feedback , image. have therefore created class called content properties:

code:
nsmutabledictionary *totalcontent = [nsmutabledictionary dictionarywithcapacity:1];  content *page1 = [[content alloc] init];  page1.questionname = @"this question 1"; page1.answer1 = @"this answer 1"; page1.answer2 = @"this answer 2"; etc  [totalcontent addobject:page1 forkey:@"first"];
however, watched lecture stanford university on itunes, , lecture talking retrieving array of dictionaries flickr work with.

presume dictionaries contain objects photo name, photo description, image, keys each. why have array of dictionary's? why not have set have done above?

i'm struggling understand these concepts. please help.
 

because array works this:

code:
arraywithobjects: zerothobject, firstobject, secondobject, thirdobject, ... nil
and automatically, based on order they're listed in, indexes within dictionary assigned, can say

code:
[array objectatindex:1]
, firstobject.

whereas if using dictionary it'd go like

code:
dictionarywithobjectsandkeys: firstobject, @"firstkey", secondobject, @"secondkey", thirdobject, @"thirdkey", ....
accessing go like
code:
[array objectatindex:@"firstkey"]
firstobject.

now, might think, okay, creating looks more messy, not big deal, right?

wrong.

because array, can access things dynamically. can say
code:
[array objectatindex:i]
and can line ever access of objects in array. whereas otherwise i'd have create separate thing each case. (there's no way know "first" corresponds 1 , "second" corresponds 2.)
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment