This file contains 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 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 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 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 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 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 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 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 | |
} | |
This file contains 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
func dayType(for day: String) -> String { | |
switch day { | |
case: "Saturday", "Sunday": return "Weekend" | |
case: "Monday", "Tuesday", "Wednessday", "Thursday", "Friday": return "Weekday" | |
default: return "This is not a valid date" | |
} | |
} | |
let result1 = dayType(for: "Sunday") //will return "Weekend" |
This file contains 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
enum Day { | |
case Sunday | |
case Monday | |
case Tuesday | |
case Wednessday | |
case Thursday | |
case Friday | |
case Saturday | |
} |