enum PostType {
case text(text: String)
case image(image: UIImage, legend: String)
case video(url: URL, duration: TimeInterval)
}
struct Post {
let date: Date
let author: String
let likes: Int = 0
let comments: [String] = []
let type: PostType
}
let textPost = Post(date: Date(), author: "John Doe", type: .text(text: "First text post"))
let imagePost = Post(date: Date(), author: "John Doe", type: .image(image: UIImage(), legend: "some picture"))
let videoPost = Post(date: Date(), author: "John Doe", type: .video(url: URL(string: "http://youtube.com")!, duration: 60))
Last active
April 26, 2017 20:54
-
-
Save alexj70/e4c8db15ad9b4d5fc99361f8cf3aa7e0 to your computer and use it in GitHub Desktop.
“Subclassing" Structs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment