Giter Site home page Giter Site logo

entries's Introduction

Entries

##Objectives Learn basics of a custom model object used for data storage, and a singleton controller to manage that those objects.

##Part 1:

###Step 1: Create an EntryController Object

  • Create an EntryController with property:
    • Entries (NSArray strong, readonly)
  • And methods:
      • (EntryController *)sharedInstance
      • (void)addEntry:(Entry *)entry
      • (void)removeEntry:(Entry *)entry
      • (void)replaceEntry:(NSDictionary *)oldEntry withEntry:(NSDictionary *)newEntry

The shared instance method should be defined to match the gist here: https://gist.github.com/jkhowland/89e24b5fb6e1b5048eb5

The addEntry method needs to create a mutable version of the controller's entries array, add the entry that's passed in, and then re-set the controller's Entries array.

The removeEntry method needs to do the reverse. It should create a mutable copy of the entries array, remove the entry that was passed in, and then re-set the controllers Entries array.

The replaceEntry method needs to find the index of the oldEntry and replace it if it exists. It should create a mutable copy of the entries array, check to see if it contains oldEntry, and then if it does find the index and replace object at index.

###Step 2: Update the controller to store the dictionary Entries to NSUserDefaults

  • Add a method 'loadFromDefaults'
    • Add a static string for the entryListKey
    • Get an arry "entryDictionaries" from NSUserDefaults for the entryListKey
    • Set self.entries to entryDictionaries
    • Call loadFromDefaults in the sharedInstance method
  • Add a method 'synchronize'
    • Save self.entries to NSUserDefaults for key entryListKey
    • Call this method at the end of addEntry and removeEntry and replaceEntry methods

##Part 2:

###Step 3: Create an Entry Object

  • Create an Entry with properties:
    • Title (NSString strong)
    • Note (NSString strong)
    • Timestamp (NSDate strong)

###Step 4: Add Dictionary Representations of Entries

  • Add two methods to the header of Entry
    • -(NSDictionary *)entryDictionary
    • -(id)initWithDictionary:(NSDictionary *)dictionary
  • Add the methods to the implementation file
  • Add a const key for each of the properties (i.e. titleKey, flagKey)
  • In the dictionary method create a mutable dictionary and then add each of the properties for their key
    • Note: You can't insert a nil object. So you'll want to check those objects before you add them
    • if (title != nil) { [dictionary addObject:title forKey:titleKey] }
  • In the init method you'll set the properties to the values for keys from the dictionary

entries's People

Contributors

jkhowland avatar

Watchers

James Cloos avatar Joseph Aranda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.