young
(rtSwift)
1
The Swift Programming Language in Self Expression:
I thought it's just the same as self.init(...)
, but seems not:
struct Foo {
let n: Int
}
extension Foo {
init(blah: Bool) {
self(n: blah ? 1 : 0) // Cannot call value of non-function type 'Foo'
}
}
Lantua
2
Should be for when self
is callable (SE-0253: Callable values of user-defined nominal types), e.g.,
struct Foo {
func callAsFunction(arg0: Int) {
print("Called with arg0: \(arg0)")
}
func bar() {
self(arg0: 7)
}
}
Foo().bar() // Called with arg0: 7
2 Likes
young
(rtSwift)
3
Maybe it shouldn't use initializer arguments
, should be callAsFunction parameters
?