Git Product home page Git Product logo

objc-interpolate-001's Introduction

Interpolate!

Objectives

  1. Use NSLog() to print a string literal to the console.
  2. Practice string formatting by using NSLog() to print interpolated strings to the console.

Instructions

Fork and clone this lab. Open the objc-interpolate.xcodeproj file and navigate to the FISAppDelegate.m file by clicking on the file name in Project Navigator in the leftmost panel know as the "Navigation area". You should see the filename appear at the top of the Code Editor; this, along with looking for the @implementation FISAppDelegate line in the code, can be used to verify that you are in the correct file.

Write your own code inside the application:didFinishLaunchingWithOptions: method before the return YES; statement. Your NSLog()s will print strings to the debug console in the bottom panel known as the "Debug area".

A. Dalek

  1. Use an NSLog() to print a string that reads "Dalek".
  • NSLog(@"Dalek");
  • Run the program with R, this should print Dalek.
  1. Now, write another NSLog() but use a single format specifier (%@) in the format string to interpolate the string that reads "Dalek" into the format string:
  • NSLog(@"%@", @"Dalek");
  • Run the program with R, this should also print Dalek.
  1. Write a third NSLog() whose format string contains five adjacent format specifiers, each format argument should be a string literal containing a single letter of the word "Dalek":
  • NSLog(@"%@%@%@%@%@", @"D", @"a", @"l", @"e", @"k");
  • Run the program with R, this should print a third Dalek.

At the end of this section, your console should print:

Dalek
Dalek
Dalek

B. Interpolate!

  1. Use NSLog() to print a string that reads "Interpolate!":
  • NSLog(@"Interpolate!");
  • Run the program with R, you should see Interpolate! printed in the debug console.
  1. Use another NSLog(), but change the format string to a string literal containing only a single format specifier (%@) and use the "Interpolate!" string as the format argument:
  • NSLog(@"%@", @"Interpolate!");
  • Run the program with R, Interpolate! should now print twice in the debug console.
  1. Write a third NSLog(), the format string should contain two format specifiers separated by a space, and both format arguments should be string literals that read "Interpolate!":
  • NSLog(@"%@ %@", @"Interpolate!", @"Interpolate!");
  • Run the program with R, this should additionally print Interpolate! Interpolate!.
  1. Write a fourth NSLog(), the format string should contain four format specifiers ending with an exclamation point (!). The four format arguments should be each syllable of the word "Interpolate", in order (Hint: In-ter-po-late).
  • NSLog(@"%@%@%@%@!", @"In", @"ter", @"po", @"late");
  • Run the program with R, Interpolate! should print an additional time.
  1. Write a fifth NSLog() similar to that previous one that separates the word into syllables, but add a hyphen (-, also "dash") between each of the format specifiers:
  • NSLog(@"%@-%@-%@-%@!", @"In", @"ter", @"po", @"late");
  • Run the program with R, this should print In-ter-po-late!.

At the end of this section, your console should print:

Interpolate!
Interpolate!
Interpolate! Interpolate!
Interpolate!
In-ter-po-late!

C. You are not The Doctor!

  1. Use an NSLog() to print a string that reads "You are not The Doctor!":
  • NSLog(@"You are not The Doctor!");
  • Run the program with R, this should print You are not The Doctor!.
  1. Write another NSLog() but use a single format specifier (%@) in the format string to interpolate the string that reads "You are not The Doctor!" into the format string
  • NSLog(@"%@", @"You are not The Doctor!");
  • Run the program with R, this should print another You are not The Doctor!.
  1. Write a third NSLog() that separates each word into a single string that gets interpolated into the format string as the list of format arguments. For this exercise, write only six adjacent format specifiers in the format string and include the punctuation mark as format argument:
  • NSLog(@"%@%@%@%@%@%@", @"You", @"are", @"not", @"The", @"Doctor", @"!");
  • Run the program with R, this should print YouarenotTheDoctor!.
  1. Similar to the NSLog() above, write a new NSLog() but add spaces between the first five format specifiers in the format string:
  • NSLog(@"%@ %@ %@ %@ %@%@", @"You", @"are", @"not", @"The", @"Doctor", @"!");
  • Run the program with R, this should print You are not The Doctor!.
  1. Write a fifth NSLog() that mixes writing the sentence between the format string and the format arguments. Start with the whole sentence written in the format string, and then replace the word "not" and the phrase "The Doctor" with format specifiers, then submit those two strings as the format arguments:
  • NSLog(@"You are %@ %@!", @"not", @"The Doctor");
  • Run the program with R, this should also print You are not The Doctor!.

At the end of this section, your console should print:

You are not The Doctor!
You are not The Doctor!
YouarenotTheDoctor!
You are not The Doctor!
You are not The Doctor!

objc-interpolate-001's People

Contributors

markedwardmurray avatar

Watchers

James Cloos avatar Ruth Mesfun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.