- 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 anNSMutableArray
argumentdeliLine
and return anNSString
object.addName:toDeliLine:
should accept anNSString
calledname
and anNSMutableArray
calleddeliLine
as arguments, and return anNSMutableArray
.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 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 B.
. 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
. Return the updateddeliLine
mutable array. -
Build the method
serveNextCustomerInDeliLine:
method. Save the first name in thedeliLine
to anNSString
object wihin the method. Then remove the first object from thedeliLine
and return the name you saved in the string object. Hint: UsingremoveObject:
could be problematic for you. There's another method onNSMutableArray
that will let you specify an object to remove by array index.