- Write custom methods to solve a few simple problems.
- Call your methods to get the results that you need.
- Run the tests to check your work.
You did such a great job last year at the Apple Worldwide Developers Conference that they've asked for you back—and now they want you to handle a few more tasks as well. It's more work than you could possible handle by yourself given the time frame, so you'll need to figure out how to pass off the intructions by creating some methods!
The speaker list is new this year, but it boasts a similarly astounding group.
- Adele Goldberg
- Edsger Dijkstra
- Joan Clarke
- Clarence Ellis
- Margaret Hamilton
- George Boole
- Tim Berners-Lee
- Jean Bartik
In addition to the name tags, the conference manager also wants you to print a personalized greeting for each speaker to inform each of them of their dressing room assignment back stage.
-
Open the
*.xcworkspace
and read the unit tests inAppDelegateSpec
. Try to understand what each test is expecting to happen. (Do not copy/paste the expected arrays from the tests into your method body. These are matchers for what your methods should produce programmatically at run time.) You'll notice that Xcode generates three errors that show up in the Issue Navigator like this: This is normal and it just means that Xcode can't find the methods that are called in the tests—but of course it can't, you haven't written them yet! -
Navigate to the
AppDelegate.h
header file. Declare three (-
) instance methods within the@interface
:
makeBadgeForSpeaker:
that accepts oneNSString
argument namedspeaker
and returns anNSString
makeAllBadgesForSpeakers:
that accepts oneNSArray
argument namedspeakers
and returns anNSMutableArray
greetAndAssignRoomsToSpeakers:
that accepts onNSArray
argument and namedspeakers
and returns anNSMutableArray
-
Navigate to the
AppDelegate.m
implementation file. Using autocomplete, fill out the names of each method and define them to returnnil
(these minimum definitions are required to get those three errors to disappear and the test build to succeed). Run the tests (⌘``U
) to make sure that the build succeeds but that the tests initially fail. -
Redefine
makeBadgeForSpeaker:
to return an interpolated string that includes the speaker's name submitted through the argument, in the manner ofHello, my name is <#speaker#>.
. Run the test that checks this method and tweak your method until it the test passes. -
Redefine
makeAllBadgesForSpeakers:
to callmakeBadgeForSpeaker:
on each string in thespeakers
array submitted through theNSArray
argument; capture its return string into a newNSMutableArray
declared within the method. Hint: Use afor
loop to iterate over the argument array and add the result of eachmakeBadgeForSpeaker:
method call to the mutable array. Return the mutable array. Then, run the test for this method and tweak your method body until the test passes. -
Redefine the
greetAndAssignRoomsToSpeakers:
method to iterate over thespeakers
argument array and create an interpolated string with each speaker's name and their dressing room number (which range from 1 through 8). The interpolated string should read:Welcome, <#speaker#>! You'll be in dressing room <#roomNumber#>.
Add each string to a mutable array. Return the mutable array, then run the test and tweak your method body until the test passes.