Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Last active December 22, 2020 10:22
Show Gist options
  • Select an option

  • Save cipolleschi/8ee3ccdf5d527dcc79e9a0a001db5dea to your computer and use it in GitHub Desktop.

Select an option

Save cipolleschi/8ee3ccdf5d527dcc79e9a0a001db5dea to your computer and use it in GitHub Desktop.
enum Attachment {
case text(info: Text)
case sticker(info: Stricker)
// common property between text and sticker.
var position: CGPoint {
switch self {
case .text(let info):
return info.position
case .sticker(let info):
return info.position
}
}
}
let aText = Text(content: "Hello World", font: UIFont.systemFont(ofSize: 18), position: .zero)
let aSticker = Stricker(fileURL: URL(string: "http://www.google.com/logo.png")!, position: .init(x: 100, y: 100), scale: 2)
let attachments: [Attachment] = [.text(info: aText), .sticker(info: aSticker)]
// print positions.
for attachment in attachments {
print(attachment.position)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment