# ios

Dmitri Sh

10/24/2019, 1:10 AM
reposting from the general channel, as no answers, maybe better luck here? Hi. A multiplatform project, android and iOS. In common code, I have an interface -
interface Idea
. When in Swift, want to have a struct implement this interface, a.k.a now as protocol in the Swiftland. Get a compiler error -
inheritance from non-protocol type 'Idea'.
In the generated objective-c file I see this -
. Reading on it, all objective c protocols are restricted to classes. So how I do get around this problem - or no getting around and have to use classes in Swift😥?


10/24/2019, 3:32 AM
You'll have to use classes. It's should just be because it's an Obj-C protocol though. That attribute prevents classes from being subclassed, which doesn't apply to protocols

Dmitri Sh

10/24/2019, 7:09 PM
ok, so a restriction to live with, thanks
👍 1

Aubrey Goodman

11/01/2019, 7:37 PM
i have found the best way to work with Kotlin interfaces in Swift is to subclass NSObject as well, like this:
Copy code
class YourIdea: NSObject, Idea { ... }

Dmitri Sh

11/03/2019, 6:16 PM
ok, but that still is a class, and I wanted to have a Swift struct implement the interface defined in Kotlin, which I now understand is impossible. Just means I have to do some manual work - Hashable, Identifiable require manual implementation in a class, while in structs swift will generate the methods automatically.

Ellen Shapiro

12/03/2019, 3:57 PM
@Dmitri Sh Late to the party but I think as long as you declare
within the same file as the primary class declaration and all the properties conform to whichever (or both), you should still get that auto-conformance in classes