- 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
*.xcworkspace
file. Declare three instance methods (beginning with-
) inFISAppDelegate.h
:
stringWithDeliLine:
should accept anNSArray
argumentdeliLine
and return anNSString
object.addName:toDeliLine:
should accept anNSString
calledname
and anNSMutableArray
calleddeliLine
as arguments, and return nothing.serveNextCustomerInDeliLine:
should accept anNSMutableArray
calleddeliLine
as an argument and return anNSString
.
-
Define them in
FISAppDelegate.m
to return a default value (ornil
) and run the tests to fail. Review what theSpec
file 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 submittedname
to thedeliLine
. Since thedeliLine
argument 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 thedeliLine
to anNSString
object within the method. Then remove the first object from thedeliLine
and return the name you removed. Hint: UsingremoveObject:
could be problematic for you. There's another method onNSMutableArray
that will let you specify an object to remove by array index.
View Deli Counter on Learn.co and start learning to code for free.