On Wed, Jul 5, 2017 at 6:52 PM, Zhao Xin <owe...@gmail.com> wrote: > For your specific question, `func signum() -> Self` returns `Self`, which > can't be used in property. > `var signum:Self { return self }` will generate an error "'Self' is only > available in a protocol or as the result of a method in a class". > So computed property can't be used here. >
This is not true, for example the following works: extension BinaryInteger { var signumAsComputedProperty: Self { if self < 0 { return -1 } else if self > 0 { return 1 } else { return 0 } } } BinaryInteger is a prosocol. But the following will also work: struct S { var computedPropertyReturningSelf: S { return self } } So I'm not sure what you mean. /Jens
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users