Iphone Developer

iPhoneCoreDataRecipes Explained…

Im going thru this Apple app and im noting my progress in understanding it.  Any comments are appreciated.

black = unanswered questions

red = my answers so far

blue = partially answered on the blog itself

green = less important, design questions maybe…

1) Why @class Recipe and @class RecipeTableViewCell
2)  They adopt a RecipeAddDelegate & NSFetchedResultsControllerDelegate protocols? YES…Ive never seen a protocol before.  I guess the NSFRC protocol class is a UIKit class but i had never seen a customcreated class be used as a protocol…COOL!
3)  Why do we declare showRecipe & configureCell methods but not the add:method or the whole bunch of others….
4)  When creating RecipeAddViewController, we do addController.delegate = self…what does this mean really?
5)  We then create a blank recipe object and set the addController.recipe = newRecipe…what is this really doing?  telling it that whatever newRecipe is created, set it to what?
6)  What does recipeAddViewController: method do?  it shows the recipe via the showRecipe method…?Its a RecipeAddViewController <protocol> method, so i just mosied on over to that code and saw that saves (or cancels) the recipe to the psc from the moc, right?
7)  The showRecipe method creates a RecipeDetailViewController and pushes it onto the stack for show. This method takes the recipe name that we created in the modalVC and sets it to the newly created RecipeDetailViewController’s recipe ivar.  This confuses me a bit cause the RecipeDetailViewController like the RecipeListTableViewControllers have no xibs.  The detailVC is actually composed of the DetailHeaderView.xib, a navcontroller which i can only assume is the one from the modalview and some other one at the bottom which i have not found yet.  Furthermore, we had set the addController.delegate =self and the addController.recipe = recipe and now we are setting detailViewController.recipe = recipe.  I understand why (we went from a modal temporary addController to a more permanent detailViewController, so all we are doing is passing the name input by the user from one to the next and storing it to the psc just in case no other data is added.
8)  numberOfSectionsInTableView calls a NSFRC method called sections just to set the count to at least 1 (is this what the NSFRCDelegate protocol called?
9)  numberOfRowsInSection calls id<NSFetchedResultsSectionInfo> … this is new but basically it returns a value for the numberOfObjects in the RC
0)  the whole RecipeTableViewCell *recipeCell is weird but ill compare it to the code in a normal section of cellForRowAtIndexPath, i bet its similar. I compared it to a regular cellForRowAtIndexPath and its exactly the same, it just switches wording.  And at the end, instead of calling the cell.textLabel.text = @”some value” it calls a method, self.configureCell passing it the recipeCell and indexPath arguments so that this other method configures that part. Im not sure why its split up like this though?
1)  configureCell actually sets the recipe to the cell.  so why make a separate function for it?
2)  didSelectRowAtIndexPath creates a recipe object and assigns it the current rowAtIndexPath value?  And then cals the showRecipe method?  I dont get this, why does it call the NSFRC and add it to a Recipe?  Its the same code the cFRAIP called.
3)  commitEditingStyle DELETE i get…but then i dont because another delete is called in tableview changedContents…
4)  fetchedResultsController is the method otherwise found in the appDelegate or FlickrFetcher singleton in our Paparazzi case….
5)  if nil, create fetchRequest, for said Entity, create sort, apply sort parameter, create aFRC with that request, set delegate to self?, set self.fetchedResultsController to aFRC, cleanup and then return the fetchedResultsController…but this doesnt execute it right?  it gets executed in the viewDidLoad right? but what does the sectionNameKeyPath part do?  And again this code of setting the object.delegate = self and then this time it adds self.fetchedResultsController = aFetchedResultsController?
6)  controllerWillChangeContent is a notification
7)  didChangeObject CHANGEINSERT is for when the user decides to insert a new recipe, CHANGEDELETE for when user decides to delete a recipe (but i thought we had this already), CHANGEUPDATE is for when we update a recipe and CHANGEMOVE is for when we move it in the tableview from a lower or higher indexpath…
8)  then there is controller:didChangeSection with CHANGEINSERT and CHANGEDELETE…what does this do?
Iphone Developer

Paparazzi Stanford CS193

I’m starting CS193p this new semester again because the Assignment this time around is Paparazzi, a Flickr client which uses CoreData and it’ll be a good experience!

I’ve started with the static view controllers and noticed I was a little rough around the edges in alloc/initting view controllers (mainly nav and tabbar). However I got thru it.

Then I moved on to Part 2 where you use the plist file to populate the CoreData model which is where I am currently and am stuck!

This time around, unlike the Twitter App, we have to use the plist file to populate the db. I’ve got the object model set up, which by the way, I figured out I can write the class files for person and photo in Paparazzi as for person in Presence and then create a CoreData object model by “importing” those class files! Except now I don’t know if i still need those class files.

So to populate the db we must read the plist file which is an array of dictionaries, right?

Figured it out with a little help (from my friends @the google auditors group).  Its definitely a seasoned programmers trick even though the guy who helped me claims to be a newbie 🙂 :

for (NSDictionary *dict in twitterIds) {}

I couldn’t figure out how to cycle thru the dictionary that was inside the array.  So this worked beautifully.

TWO important concepts:

1) Singletons: Are like the UIApplicationDelegate class.  They are special classes which have certain methods you want to import or access from other class files (which provide certain functionality) and its not bound to your UIApplicationDelegate.  So you dont violate that rule of thumb.  Basically you declare a sharedInstance of that singleton class “FlickrFetcher” in your code, then you can being to call all methods from that class.  I guess later on ill understand why we dont just adopt the class as a protocol, which would seem to me to provide the same functionality.

2) CoreData: Aside from your singleton class declaring the moc, mom and psc…you need to declare a new moc in the class where you will be using the code you ‘access via singleton’.  Then you allocate your objects just like any Class Object Files as the Person objects in Presence from last semester and start using them.  Dont forget to save them to the psc, dont just leave them in the moc or youll lose them 🙂

Translate »