tezvyn:

Exposing Swift classes to Objective-C

Source: interviewintermediate

WHAT IT TESTS: Swift-to-ObjC interop rules. OUTLINE: subclass NSObject or mark members @objc, import the generated ModuleName-Swift.h, and accept that Swift-only types like enums with associated values cannot cross.

WHAT IT TESTS: knowing the constraints of the Objective-C runtime when surfacing Swift code. ANSWER OUTLINE: make the Swift class inherit from NSObject or mark it and its members @objc (or use @objcMembers), then import the compiler-generated ModuleName-Swift.h in your Objective-C files. Only constructs the Objective-C runtime understands can cross: no generics, no structs, no enums with associated values, no tuples, no Swift-only protocols with associated types.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Exposing Swift classes to Objective-C · Tezvyn