With our module fully defined, let's see how things look from outside the module. We need to build the module to make it available to the playground. Now, select the playground; it should have a statement that imports the AppleInc module:
import AppleInc
First, let's look at the most accessible class that we created--SwiftLanguage. Add the following to the playground:
class WinSwift: SwiftLanguage {
override func versionNumber() -> Float {
return 5.0
}
override func supportedPlatforms() -> [String] {
var supported = super.supportedPlatforms()
supported.append("Windows")
return supported
}
}
Since SwiftLanguage is open, we can subclass it to add more supported platforms and increase the version number.
Next, let's create an instance of the Apple class and see how we can interact with it:
let apple = Apple()
let keith = Person(name: "Keith Moon")
apple.newEmployee(person: keith)
print("Current CEO: \(apple.ceo.name)")
let jony = Person(name: "Jony Ive")
apple.ceo = jony // Doesn't compile
We can create Person and provide it to Apple as a new employee since the Person class and the newEmployee method are declared as public. We can retrieve information about the CEO, but we aren't able to set a new CEO as we defined the property to be private (set).
Another of the public interfaces provided by the module is the ability to buy an iPhone from the Apple Store:
// Buy new iPhone
let boughtiPhone = apple.store.selliPhone(ofModel: .iPhone6S)
// This works
// Try and create your own iPhone
let buildAndPhone = AppleiPhone(model: .iPhone6S) // Doesn't compile
We can retrieve a new iPhone from the Apple Store because we declared the selliPhone method as public, but we can't create a new iPhone directly as the iPhone's init method is declared as fileprivate.