Skip to content

Instantly share code, notes, and snippets.

@alexvbush
Last active March 23, 2018 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexvbush/2a587bf3d5a660e1239a7206be3d1659 to your computer and use it in GitHub Desktop.
Save alexvbush/2a587bf3d5a660e1239a7206be3d1659 to your computer and use it in GitHub Desktop.
import Foundation
struct User {
let firstName: String
let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
class YourViewControllerOrSomeOtherPlace {
var user: User?
func viewDidLoadOrSomeOtherMethod() {
if let user = user {
print("rendering UI for the user since we clearly have one")
print("user's full name is: \(user.fullName())")
} else {
print("rendering UI for no-user case")
print("Hi no-user, you should really sign in!")
}
}
}
let aVCWithAUser = YourViewControllerOrSomeOtherPlace()
aVCWithAUser.user = User(firstName: "Joe", lastName: "Dow")
aVCWithAUser.viewDidLoadOrSomeOtherMethod()
print("=================")
let aVCWithNoUser = YourViewControllerOrSomeOtherPlace()
aVCWithNoUser.viewDidLoadOrSomeOtherMethod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment