binding-tools-for-swift
binding-tools-for-swift copied to clipboard
[SoM] SwiftRuntimeLibrary could be made friendlier with some implicit operators
SwiftAnyObject which is used to represent the AnyObject type in swift has a static converter, but it might be nice to have an implicit operator for ISwiftObject.
SwiftImplicitlyUnwrappedOptional<T> could also benefit from this.
In swift, this is used to represent the type T!.
SwiftOptional<T> could also benefit from this from C# Optional<T>.
SwiftString could use benefit to C# string.
Would also be somewhat better with explicit operators.
This was discussed on discord and this is the conclusion for now: Sebastien: @steve.hawley @chamons yes, been there before. implicit op have bitten us a few times. WRT to NSString there's a cost to the operation that gets hidden from the developer (a string can be converted multiple times). Also we had, less common, issues (e.g. localization) with subclasses of NSString that could not convert back correctly (from string to NSString). So it's not always lossless - even if it seems to be
Steve: @sebastien that's a good point - but the good news is that Swift.String is a value type and can't be subclassed, so that doesn't apply. I'm with you on the tradeoff between easy-to-use and hidden cost. I think maybe the right thing to do in this case is to no do the implicit operator and see if any asks for it and put this discussion into the issue for the future when it comes up again.
I agree that we can wait and see, we can always add implicit operators later.