Skip to content

Instantly share code, notes, and snippets.

@davideme
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davideme/e594e223dd07b0c7c888 to your computer and use it in GitHub Desktop.
Save davideme/e594e223dd07b0c7c888 to your computer and use it in GitHub Desktop.
// This protocol cannot be implemented by a enum.
// Because enums may not contain stored properties
protocol SomeProtocol {
var mustBeSettable: Bool { get set }
}
struct SomeStruct: SomeProtocol {
var mustBeSettable:Bool
}
// Compiler Error
//enum SomeEnum: SomeProtocol {
// var mustBeSettable:Bool
//}
class SomeClass: SomeProtocol {
var mustBeSettable:Bool = true
}
var s = SomeStruct(mustBeSettable: true)
s.mustBeSettable = false
var c = SomeClass()
c.mustBeSettable = false
// Compiler Error, SomeProtocol could be an enum
func someFunction(foo:SomeProtocol){
foo.mustBeSettable = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment