- Practice utilizing the debugging suite while exercising what you've already learned.
This lab contains a few code challenges based upon manipulating strings and arrays in different ways by using loops and conditionals; it's all stuff you should already have practiced with. Now, get practice incorporating your new knowledge of debugging tools into your workflow. Use NSLog()
, breakpoints, po
in the console, and the variable viewer to get glimpses inside your code as it's running.
Open the *.xcworkspace
file and navigate to the FISAppDelegate.h
header file to declare the following methods:
-
stringByRollCallingDwarfsInArray:
that takes oneNSArray
argument calleddwarfs
and returns anNSString
. -
arrayOfPlaneteerShoutsFromArray:
that takes oneNSArray
argument calledpowers
and returns anNSArray
. -
summonCaptainPlanetWithPowers:
that takes oneNSArray
argument calledpowers
and returns anNSString
. -
firstPremiumCheeseInStock:premiumCheeseNames:
that takes twoNSArray
arguments calledcheesesInStock
andpremiumCheeseNames
, and returns anNSString
. -
arrayByConvertingMoneyBagsIntoPaperBills:
that takes oneNSArray
argumentmoneyBags
and returns anNSArray
.
Navigate to the FISAppDelegate.m
implementation file and declare each method to return nil
. Run the tests (โ``U
) to see that they fail. Solve each method implementation to pass the test:
-
To improve workplace safety, Doc has suggested that the seven dwarfs roll call themselves when entering or leaving the mine. Write the implementation for
stringByRollCallingDwarfsInArray:
to take the array of dwarf names and create a string that gives each dwarf a list number (1.
to7.
), and separates each number & name with a|
("pipe"). Look at the test file to see exactly what you need to generate, but don't hard code the answer! Create the expected string programmatically by appending each dwarf's name in an interpolated string.
Hint: When a test's "expected:" value and its "got:" value don't fit on the red highlighted line the shows up in the Code Editor when the test fails, remember that you can view the values in their entireties via the Reports navigator. -
Let's help the Planeteers get the gusto they need to summon Captain Planet! Write the implementation of
arrayOfPlaneteerShoutsFromArray:
to take each of the five Planeteer's powers in the argument array and convert them into uppercase while adding an!
("exclamation point") to the end. Return the array of altered strings. Again, don't hard code the answer. Solve this problem programmatically with loops and string interpolation! -
Now that the Planeteers have practiced their shouts, they need to combine their powers to take pollution down to zero! Write the implementation for
summonCaptainPlanetWithPowers:
to take the five Planeteers' powers and combine them into the Planeteer phrase that summons Captain Planet!- The phrase begins with "Let our powers combine:",
- Then each Planeteer shouts their power in sequence,
- Then the phrase ends with "Go Planet!".
- Each piece of the phrase should be separated by a new line (
\n
), and don't forget to capitalize "Planet!" as proper noun.
Hint: You could try calling the method you just wrote inside this method implementation by calling[self arrayOfPlaneteerShoutsFromArray:powers]
and capturing its return. Sending a method call toself
, in this case, tells ourFISAppDelegate
object to call a method on itself.
-
Jerry Mouse has expensive taste in cheese and he only eats the best. Write the implementation for
firstPremiumCheeseInStock:premiumCheeseNames:
to compare the two argument arrays and return the first cheese inpremiumCheeseNames
that is also in thecheesesInStock
array. If there are no cheeses common to both arrays, then the method should return@"No premium cheeses in stock."
so Jerry knows to look somewhere else. -
Scrooge McDuck is a real financial conservative and still keeps his money in dollar coins! However, he's decided to try out this new thing called "paper bills" (he hears they're the next big thing); he's brought several bags (strings) of coins to you, a bank teller, to convert into paper money. Write the implementation for
arrayByConvertingMoneyBagsIntoPaperBills:
to count the dollar coins (one coin is represented by one$
) in each string in Scrooge's array into an equivalent paper bill (a string in the manner of@"$20"
). Look at the tests to clarify the scenario, but avoid hard coding the answer!
View Cartoon Collections on Learn.co and start learning to code for free.