Coder Social home page Coder Social logo

objc-applesandholidays-wdc01-seng-ft-060120's Introduction

Apples And Holidays

Objectives

  1. Use NSPredicate to filter objects in an array.
  2. Practice accessing a nested collection.

Instructions

In the FISAppDelegate.h header file, declare the following seven instance methods, then navigate to the FISAppDelegate.m implementation file and define them all to either return nil or return a test object of the correct kind:

  • pickApplesFromFruits: which takes one NSArray argument fruits and returns an NSArray.

  • holidaysInSeason:inDatabase: which takes two arguments, an NSString called season and an NSDictionary called database, and returns an NSArray.

  • suppliesInHoliday:inSeason:inDatabase: which takes three arguments: an NSString called holiday, an NSString called season, and an NSDictionary called database; and returns an NSArray.

  • holiday:isInSeason:inDatabase: which takes three arguments: an NSString called holiday, an NSString called season, and an NSDictionary called database; and returns a BOOL.

  • supply:isInHoliday:inSeason:inDatabase: which takes four arguments: an NSString called supply, an NSString called holiday, an NSString called season, and an NSDictionary called database; and returns a BOOL.

  • addHoliday:toSeason:inDatabase: which takes three arguments: an NSString called holiday, an NSString called season, and an NSDictionary called database; and returns an NSDictionary.

  • addSupply:toHoliday:inSeason:inDatabase: which takes four arguments: an NSString called supply, an NSString called holiday, an NSString called season, and an NSDictionary called database; and returns an NSDictionary.

Top-tip: Hitting enter while you cursor is in the space between the argument components in a method declaration line will align the components of the method name by the : ("colon") on a new line.

Run the tests with ⌘``U to see that most of them fail.

Apple Picker

And I keep hearing from the cellar bin
The rumbling sound
Of load on load of apples coming in.

After Apple Picking, Robert Frost

Write out the implementation body for the pickApplesFromFruits: method so that it returns an NSArray of all of the occurrences of the string @"apple" in the argument array fruits. Think about how you can filter the argument array using NSPredicate.

Hint: Use the self keypath when filtering an array of strings.

Holiday Supplies

  1. Look at the HolidayTests file to review the structure of the suppliesByHolidayAndSeason dictionary at the top of the file. This dictionary is submitted to the database argument of the method calls across the test file, meaning that it's the collection you'll be working with. You should be able to decipher that this is a nested collection: the first layer is a static dictionary of "season" keys; each season key is bound to a mutable dictionary of "holiday" keys; each holiday key is bound to mutable array of "supplies" relevant to that holiday.
  2. Write the implementations for the rest of the methods, running the tests as you finish each one to make sure its tests pass:
  • holidaysInSeason:inDatabase: to return an array of all of the "holiday" keys in the sub-dictionary associated with the submitted "season" argument.

  • suppliesInHoliday:inSeason:inDatabase: to return the mutable array of all of the supplies for the submitted "holiday" in the submitted "season".

  • holiday:isInSeason:inDatabase: to return whether or not the submitted "season" contains a key that matches the "holiday" argument.

  • supply:isInHoliday:inSeason:inDatabase: to return whether or not the submitted "holiday" in the submitted "season" contains in its array the submitted "supply" string.

  • addHoliday:toSeason:inDatabase: to create a new key-value pair in the submitted "season" key's sub-dictionary that uses the submitted "holiday" as the key and sets up an empty mutable array as its value.

  • addSupply:toHoliday:inSeason:inDatabase: to insert the submitted "supply" argument into the mutable array of the submitted "holiday" key in the sub-dictionary of the submitted "season" key.

View Apples And Holidays on Learn.co and start learning to code for free.

objc-applesandholidays-wdc01-seng-ft-060120's People

Contributors

markedwardmurray avatar altyus avatar zdrossman avatar chrisgonzgonz avatar fs-lms-test-bot avatar jmburges avatar sarogers avatar fislabstest avatar flatiron-bot avatar ipc103 avatar

Watchers

Kaitlin Vignali avatar Mohawk Greene avatar Victoria Thevenot avatar raza jafri avatar  avatar Joe Cardarelli avatar  avatar  avatar Ben Oren avatar Matt avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Dominique De León avatar  avatar Vicki Aubin avatar Maxwell Benton 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.