New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Init method not visible to ObjC #11
Comments
Thanks for pointing this out. As you can guess from this bug, I have no experience with Objective-C, so I’m gonna need a little help on this one. How would you go around fixing this? I’m not sure if/how closures are represented in Obj-C, or how to represent them in types that can be bridged. If you could possibly file a PR, that would be great. |
You can add a init constructor like this (if you don't care about the animation blocks) and it will be bridged to objective-c public init(presentDuration: TimeInterval, dismissDuration: TimeInterval) {
self.presentDuration = presentDuration
self.presentAnimation = nil
self.presentCompletion = nil
self.dismissDuration = dismissDuration
self.dismissAnimation = nil
self.dismissCompletion = nil
} |
Thanks! Is there any way to represent the various closures in Obj-C though? Would hate for Obj-C users to not be able to access the full capabilities. |
Could you folks take a look at the |
Works fine for me, tested that all the callbacks work. You might consider adding an additional objc init that only has args for the various blocks/closures so we don't have to guess at durations to provide if we just want it to use the defaults. |
Nice, good to know. Just put this out there to see if the closures work |
Anyone know how to mark a method as visible in Objective-C but not in Swift? |
I don't think you can do that. If you're wanting to just have one ctor, you could switch those public init(presentDuration: NSNumber? = nil,
presentAnimation: (() -> ())? = nil,
presentCompletion: ((Bool) -> ())? = nil,
dismissDuration: NSNumber? = nil,
dismissAnimation: (() -> ())? = nil,
dismissCompletion: ((Bool) -> ())? = nil) {
self.presentDuration = presentDuration?.doubleValue;
self.presentAnimation = presentAnimation
self.presentCompletion = presentCompletion
self.dismissDuration = dismissDuration?.doubleValue;
self.dismissAnimation = dismissAnimation
self.dismissCompletion = dismissCompletion
} Of course, that forces Swift callers to pass in NSNumber instances if they choose to specify durations, so you may not be happy with that. |
Actually, I just tried that and it doesn't affect swift callers, so this still works fine: let transition = DeckTransitioningDelegate(presentDuration: 2.5) |
Hmm, good find. One tiny issue is it breaks existing code if you've set it up with types variables and not just numbers the type for which can be inferred to be whatever is needed. Not sure about this |
|
You seem to be using optional parameters within the constructors which can't be bridged to ObjC.
Thus this library is not usable in ObjC projects.
See: https://stackoverflow.com/questions/26470771/swift-init-not-visible-in-objecitve-c
The text was updated successfully, but these errors were encountered: