- Write custom methods that take arguments and return results.
- Use a method as a helper method.
- Read and run unit tests to check your work.
The local deli is putting in a new computerized queue to keep track of their customers and improve productivity.
- Open the
*.xcworkspacefile. Declare three instance methods (beginning with-) inFISAppDelegate.h:
stringWithDeliLine:should accept anNSArrayargumentdeliLineand return anNSStringobject.addName:toDeliLine:should accept anNSStringcallednameand anNSMutableArraycalleddeliLineas arguments, and return nothing.serveNextCustomerInDeliLine:should accept anNSMutableArraycalleddeliLineas an argument and return anNSString.
-
Define them in
FISAppDelegate.mto return a default value (ornil) and run the tests to fail. Review what theSpecfile expects from your methods. -
Build the
stringWithDeliLine:method to:
- if there are no customers in line, return the string
The line is currently empty., - otherwise, return a formatted string beginning with
The line is:and appending every customer in the queue on a new line (\n) beginning with their number in the queue, e. g.1. Anita. Remember, these customers are humans so they count from one—not from zero like computers.
-
Build the method
addName:toDeliLine:method to add the submittednameto thedeliLine. Since thedeliLineargument is mutable, this method does not need to return an array; the array argument is modified in-place. -
Build the method
serveNextCustomerInDeliLine:method. Save the first name in thedeliLineto anNSStringobject within the method. Then remove the first object from thedeliLineand return the name you removed. Hint: UsingremoveObject:could be problematic for you. There's another method onNSMutableArraythat will let you specify an object to remove by array index.
View Deli Counter on Learn.co and start learning to code for free.