Created
June 25, 2019 18:56
-
-
Save kyle-morton/5e7512cf2a422e3a603fc840c8bca473 to your computer and use it in GitHub Desktop.
small playground used to learn about swift optionals and syntax
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
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