Git Product home page Git Product logo

tasks's Introduction

Tasks

##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 a Task Object

  • Create a Task with properties:
    • Title (NSString strong)
    • Flag (BOOL assign)
    • Note (NSString strong)
    • CompletedDate (NSDate strong, readonly)
  • And method:
    • -(void)markCompleted:(BOOL)completed

The markCompleted method should check and if completed == YES then it should set the date to now, otherwise it should set the date to nil.

###Step 2: Create a TaskController Object

  • Create a TaskController with properties:
    • Tasks (NSArray strong, readonly)
  • And methods:
    • +(TaskController *)sharedInstance
    • -(void)addTask:(Task *)task
    • -(void)removeTask:(Task *)task

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

The addTask method needs to create a mutable version of the controller's tasks array, add the task that's passed in, and then re-set the controller's Tasks array.

The removeTask method needs to do the reverse. It should create a mutable copy of the tasks array, remove the task that was passed in, and then re-set the controllers Tasks array.

##Part 2:

###Step 3: Add Dictionary Representations of Tasks

  • Add two methods to the header of Task
    • -(NSDictionary *)taskDictionary
    • -(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

###Step 4: Update the controller to store the dictionary Tasks to NSUserDefaults

  • Update the setter method of Tasks array
    • Store the tasks array in _tasks
    • Create a new mutable array
    • Iterate through the tasks and convert each one to a dictionary
    • Add that dictionary to the mutable array
    • Store the new array of dictionaries to NSUserDefaults
  • Update the sharedInstance method
    • Get the array of dictionaries from NSUserDefaults
    • Create a new mutable array
    • Iterate through the list of dictionaries, convert each one to a task and add to the mutable array
    • Set self.tasks to the mutable array

tasks's People

Contributors

jkhowland avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.