3 ms·
> In swift you do mymethod?.call(...) Where method can be nil and it has the same effect. No, it doesn't. (You probably meant object?.mymethod()). If mymethod
by mojuba 4y ago
> In swift you do mymethod?.call(...) Where method can be nil and it has the same effect.
No, it doesn't. (You probably meant object?.mymethod()). If mymethod returns int, then in Swift the result of this expression is strictly Optional<Int>, whereas in Objective-C it's Int defaulting to zero if object is nil. The implications in terms of safety are significant.
- Cloudef 4y agoI did mention object?.mymethod as well, method?.call is needed if you want to call on nullable method itself in a safe way.
- setr 4y agoDefaultZero = Object?.mymethod() ?? 0; Optional-null + null-coalescing is strictly more flexible than obj-c’s behavior, while more sanely defined, with very minimal syntax