Open harkmall opened 9 years ago
I'm facing exactly the same problem...i would love to use this great library in Objective-C
I was trying to do the same thing here. From Apple Documentation:
You’ll have access to anything within a class or protocol that’s marked with the @objc attribute as long as it’s compatible with Objective-C. This excludes Swift-only features such as those listed here:
- Generics
- Tuples
- Enumerations defined in Swift
- Structures defined in Swift
- Top-level functions defined in Swift
- Global variables defined in Swift
- Typealiases defined in Swift
- Swift-style variadics
- Nested types
- Curried functions
So the other overloaded methods are not available in the ObjC interface.
What I did was removing the AlertStyle enum from the methods, and used an Int type, redefining the enum elsewhere to match the AlertStyle enum.
@nmizoguchi can you please explain how you did it? I am facing same issue.
@susrisha XCode won't generate the Obj-C interface unless there are no Swift Only input or output in the method, because it doesn't know how to do it (the reference to this is in the previous post).
If you look in the SweetAlert.swift, you'll see this enum:
public enum AlertStyle { case Success,Error,Warning,None case CustomImag(imageFile:String) }
This CustomImag
property is not supported by Obj-C.
Also, the methods to show an alert all use this enum, and that is why it isn't available in Objective-C environment.
One solution is to remove the CustomImag
, and in the method:
public func showAlert(title: String, subTitle: String?, style: AlertStyle,buttonTitle: String,buttonColor: UIColor,otherButtonTitle: String?, otherButtonColor: UIColor?,action: ((isOtherButton: Bool) -> Void)? = nil)
edit the case where CustomImag is used. This will disable Custom Images, but you'll be able to use it in Objective-C code.
Any fix yet?
How do I use this in my Objective-C project. It lets me do the :
but none of the customizing like adding a subtitle or changing the type of alert. Any help is appreciated. Thanks!