colinfwalsh / swift-boat-ios-0616

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift — Boat

Objectives

  1. Create a new class.
  2. Give the class properties.
  3. Write a designated initializer for a class.
  4. Write a convenience initializer for a class.

Instructions

Open the swift-boat.xcworkspace file.

  1. Create a new Swift file titled Boat.swift to hold a new class.

  2. In the new file, create a new class definition for a custom class named Boat. Remember: classes in Swift don't need to inherit from NSObject!

  3. Give your new Boat class four properties:

  • a string constant named name,
  • a mutable array of Strings named sailors,
  • a mutable Double named maxSpeedKnots, and
  • a mutable Double named speedKnots with a default value of zero.
  1. Write a designated initializer that covers the name, sailors, and maxSpeedKnots properties. It should not interact with speedKnots which already has a value of zero.

  2. Write a convenience initializer that accepts arguments for name and maxSpeedKnots. It should call the designated initializer, passing its two arguments along, and passing an empty array of type String to the sailors argument.

View this lesson on Learn.co

About

License:Other


Languages

Language:Swift 73.7%Language:Shell 22.0%Language:Ruby 4.2%