1

I created a Swift class for a notification view (UIView) that has an ENUM setup for the type of notification to be set (i.e. for defining colors, text, etc for the different predetermined types of notifications).

I need to be able to call this from my existing Objective-C class, but whenever I put the ENUM in the Swift function arguments, Objective-C can't find that specific function (it is even removed from the "-Swift.h" file.

Is it possible to do this?

Here is my Swift Function:

enum NotificationViewType: Int
{
    case Custom = 0
    case Success
    case Error
    case Warning
}

init(inViewController: UIViewController, forType: NotificationViewType, duration: Float = 0.0, leftButtonHandler: () -> Void, rightButtonHandler: () -> Void)
{
    ....
}
JimmyJammed
  • 9,598
  • 19
  • 79
  • 146

1 Answers1

0

I can't find anything that explicitly says Swift enumerations are not supported in Objective-C, but a quick glance over their documentation shows that they are a feature of Swift that is quite alien to C-style enumerations.

Your best bet for an interoperable enumeration is to declare it first in Objective-C and then use it in both languages.

See here in the documentation on using C enumerations in Swift. I could find no comparable documentation talking about Swift enumerations in (Objective-)C.

Gregory Higley
  • 15,923
  • 9
  • 67
  • 96