This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
let name: String | |
var age: Int | |
init(name: String, age: Int) { | |
self.name = name | |
self.age = age | |
} | |
func celebrateBirthday() { | |
self.age += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Abel: Youtuber = Youtuber(channelName:"Swift",subscribers:32,name:"Abel",age:27) | |
Abel.celebrateBirthday() //Happy birthday Abel | |
Abel.age //27 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Youtuber: Person { | |
let channelName: String | |
var subscribers: Int | |
//we need to pass in the name & age of the Youtuber Person | |
init(channelName: String, subscribers: Int, name: String, age: Int) { | |
self.channelName = channelName | |
self.subscribers = subscribers | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
var name: String | |
var gender: String = "Male" | |
init(name: String) { | |
self.name = name | |
} | |
} | |
class Foreigner: Person { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Person { | |
var firstname: String | |
var middlename: String | |
var lastname: String | |
} | |
//this will definitely work because i have a middlename | |
let me = Person(firstname: "Abel", middlename: "abel", lastname: "Adeyemi") | |
//This will throw an error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Person { | |
var firstname: String | |
var middlename: String? //we created the optional with the ? | |
var lastname: String | |
func fullName() -> () { | |
print("Your fullname is \(firstname) \(middlename!) \(lastname)") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Person { | |
var firstname: String | |
var middlename: String? | |
var lastname: String | |
func fullName() -> () { | |
print("Your fullname is \(firstname) \(middlename!) \(lastname)") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Person { | |
var firstname: String, var middlename: String?, var lastname: String | |
func fullName() -> () { | |
if (middlename != nil) { | |
print("Your fullname is \(firstname) \(middlename!) \(lastname)") | |
} else { | |
print("Your fullname is \(firstname) \(lastname)") | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Person { | |
var firstname: String, var middlename: String?, var lastname: String | |
func fullName() -> () { | |
if let middlename: String = middlename { | |
print("Your fullname is \(firstname) \(middlename) \(lastname)") | |
} else { | |
print("Your fullname is \(firstname) \(lastname)") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Person { | |
var firstname: String, var middlename: String?, var lastname: String | |
func fullName() -> () { | |
guard let middlename = middlename else { | |
print("Your fullname is \(firstname) \(lastname)") | |
return | |
} | |