Skip to content

Instantly share code, notes, and snippets.

@kyle-morton
Created June 25, 2019 18:56
Show Gist options
  • Save kyle-morton/5e7512cf2a422e3a603fc840c8bca473 to your computer and use it in GitHub Desktop.
Save kyle-morton/5e7512cf2a422e3a603fc840c8bca473 to your computer and use it in GitHub Desktop.
small playground used to learn about swift optionals and syntax
import UIKit
var str = "Hello, playground"
func sayTitle(title: String) {
print("Title: \(title)")
}
class Movie {
var title: String?
var year: String?
init(title: String, year: String) {
self.title = title
self.year = year
}
}
class MyError : Error {
init() {
}
}
let myMovie = Movie(title: "Batman", year: "1989")
myMovie.title
print("message: \(str)")
print("movie: \(myMovie)")
sayTitle(title: myMovie.title!)
if let movieTitle = myMovie.title {
print("movie title in if: \(movieTitle)")
}
myMovie.title = nil
guard let movieTitle = myMovie.title else {
print("no movie title found!")
throw MyError()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment