Last active
April 16, 2020 20:13
-
-
Save agoiabel/bdd898d752f28dfaee38771c3c981f9a to your computer and use it in GitHub Desktop.
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 | |
let anotherPerson = Person(firstname: "Abel", middlename: nil, lastname: "Adeyemi") |
What’s the error message
You should have it in a Struct or Class.
import UIKit;
struct 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)")
}
}
let me = Person(firstname: "Abel", middlename: "Agoi", lastname: "Adeyemi");
me.fullName();
Thankyou
It shows me error if I use the class . Send me code using class keyword.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting error executing the same code. Please let me know the solution