- Create a new class.
- Give the class properties.
- Write a designated initializer for a class.
- Write a convenience initializer for a class.
Open the swift-boat.xcworkspace
file.
-
Create a new Swift file titled
Boat.swift
to hold a new class. -
In the new file, create a new class definition for a custom class named
Boat
. Remember: classes in Swift don't need to inherit fromNSObject
! -
Give your new
Boat
class four properties:
- a string constant named
name
, - a mutable array of
String
s namedsailors
, - a mutable
Double
namedmaxSpeedKnots
, and - a mutable
Double
namedspeedKnots
with a default value of zero.
-
Write a designated initializer that covers the
name
,sailors
, andmaxSpeedKnots
properties. It should not interact withspeedKnots
which already has a value of zero. -
Write a convenience initializer that accepts arguments for
name
andmaxSpeedKnots
. It should call the designated initializer, passing its two arguments along, and passing an empty array of typeString
to thesailors
argument.