an array of self-defined swift object can't be converted to objective-c type

58 Views Asked by At

A newbie to swift

I'm doing a mixed-language (Swift & Objective-C) program, and encounter an error when trying to import Swift into Objective-C

here is my code

@objc public enum ItemType: Int {
  case left, right
}
public class MyClass {
  @objc var items: [ItemType] = []
}

Here is the error enter image description here

It seems that there's something wrong about the ItemType but I do see the definition of ItemType in my -swift.h file

Could any one give me a hint?

1

There are 1 best solutions below

0
On BEST ANSWER

Swift and Objective-c enums is very different in their nature. Old Objective-c enum is very little subset of modern Swift enum. Currently compiler doesn't know how to use Swift's enum from Objective-c code so they can't be @objc type. MyClass also can't be @objc type while it contain swift's enum.