Coder Social home page Coder Social logo

ioshopping-cart's Introduction

Shopping Cart

Objectives

  1. Create a custom class file that inherits from NSObject.
  2. Import another custom class.
  3. Declare a property on a custom class.
  4. Write methods for the custom class to perform on a property that it owns.

Instructions

Open the iOShoppingCart.xcworkspace file. You should see the familiar FISAppDelegate class and a FISItem class set up already.

I. Create a new FISShoppingCart class that inherits from NSObject.
Import FISItem into FISShoppingCart's header file.
Declare one property, an NSMutableArray called items.
Declare the following 11 methods in FISShoppingCart.h:

  • calculateTotalPriceInCents which takes no arguments and returns an NSUInteger,
  • addItem: which takes one FISItem argument called item and provides no return,
  • removeItem: which takes one FISItem argument called item and provides no return,
  • removeAllItemsLikeItem: which takes on FISItem argument called item and provides no return,
  • sortItemsByNameAsc which takes no arguments and provides no return,
  • sortItemsByNameDesc which takes no arguments and provides no return,
  • sortItemsByPriceInCentsAsc which takes no arguments and provides no return,
  • sortItemsByPriceInCentsDesc which takes no arguments and provides no return,
  • allItemsWithName: which takes one NSString argument called name and returns an NSArray,
  • allItemsWithMinimumPriceInCents: which takes one NSUInteger argument and returns an NSArray, and
  • allItemsWithMaximumPriceInCents: which takes one NSUInteger argument and returns an NSArray.

Define the initial method implementations in FISShoppingCart.m to either:

  • return nil for methods that provide a return, or
  • do nothing for methods that do not provide a return.

Run the tests with โŒ˜ U to check that the tests in FISShoppingCartSpec.m initially fail.

II. Complete each of the method implementations so that they pass their tests:

  1. calculateTotalPriceInCents should calculate the sum of the priceInCents property of all the items in the items array. Naturally, this should return 0 if the items array is empty.

  2. addItem: should add the submitted item to the items array, even if the item is already in the items array (sometimes you just need to stock up on hot pockets!).

  3. removeItem: should remove a single occurrence of an item in the items array.
    Hint: Use NSMutableArray's indexOfObject: andremoveObjectAtIndex: method.

  4. removeAllItemsLikeItem: should remove all occurrences of an item in the items array.

  5. sortItemsByNameAsc should sort the contents of the items array by their name property in ascending order (alphabetical).
    Hint: Use NSSortDescriptor for these methods.

  6. sortItemsByNameDesc should sort the contents of the items array by their name property in descending order.

  7. sortItemsByPriceInCentsAsc should sort the contents of the items array by the priceInCents property in ascending order.

  8. sortItemsByPriceInCentsDesc should sort the the contents of the items array by the priceInCents property in descending order.

  9. allItemsWithName: should return an array containing only the items whose name property matches the argument string.
    Hint: Use NSPredicate for these methods.

  10. allItemsWithMinimumPriceInCents: should return an array containing only the items whose priceInCents property is greater than or equal to the argument integer.

  11. allItemsWithMaximumPriceInCents: should return an array containing only those items whose priceInCents property is less than or equal to the argument integer.

View Shopping Cart on Learn.co and start learning to code for free.

View Shopping Cart on Learn.co and start learning to code for free.

ioshopping-cart's People

Contributors

annjohn avatar chrisgonzgonz avatar fislabstest avatar fs-lms-test-bot avatar ipc103 avatar jimcampagno avatar markedwardmurray avatar misterfifths avatar sarogers avatar zdrossman avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ioshopping-cart's Issues

Read description: Items in physical folders but not in pbxproj

FISCart.h/m and FISItem.h/m already exist for iOSShoppingCart, but aren't populated in the project nav. if you try to create them again (duplicating them), xcode wont know which classes to look at and your code will never be right. Not sure if I missed some prompt that alerted me to this, but that definitely was a fun time

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.