Skip to content

Instantly share code, notes, and snippets.

@tikidunpon
Last active July 2, 2018 15:33
Show Gist options
  • Save tikidunpon/e80024534564a50884ec78211c5f4d9a to your computer and use it in GitHub Desktop.
Save tikidunpon/e80024534564a50884ec78211c5f4d9a to your computer and use it in GitHub Desktop.
// 以下サイトの4.1.2RELEASEで動きます。
// http://online.swiftplayground.run/
import Foundation
enum ViewMode: Equatable {
case normal
case createPosition(CGPoint)
case editMode
var isCreatePosition: Bool {
switch self {
case .createPosition:
return true
default:
return false
}
}
}
let current: ViewMode = .normal
let next: ViewMode = .createPosition(.zero)
// 普通にswitchではだめ?
switch next {
case .createPosition:
print("is create Position")
default:
print("is not createPosition")
}
// それかcomputed property化?
if !next.isCreatePosition {
print("is not createPosition")
}
@tikidunpon
Copy link
Author

これも良さそう

if case .createPosition(let _) = current {} else {  
  print("is not createPosition") 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment