reposting from the general channel, as no answers,...
# ios
d
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 -
__attribute__((objc_subclassing_restricted))
. 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😥?
b
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
d
ok, so a restriction to live with, thanks
👍 1
a
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 { ... }
d
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.
e
@Dmitri Sh Late to the party but I think as long as you declare
Hashable
or
Equatable
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