11

I am working on a project where I must extend an objective-c application with some Swift code. So I need to access the Swift code from an .m file.

I imported the generated Swift.h file and now I have access to the methods, but not to the global variables.

Is it possible to do that?

Thanks!

user3612623
  • 245
  • 3
  • 13

1 Answers1

25

According to Apple's docs on Swift and Objective-C type compatibility the answer is no:

When you create a Swift class that descends from an Objective-C class, the class and its members—properties, methods, subscripts, and initializers—that are compatible with Objective-C are automatically available from Objective-C. This excludes Swift-only features, such as those listed here:

  • Generics
  • Tuples
  • Enumerations defined in Swift without Int raw value type
  • Structures defined in Swift
  • Top-level functions defined in Swift
  • Global variables defined in Swift
  • Typealiases defined in Swift
  • Swift-style variadics
  • Nested types
  • Curried functions
  • 4
    __Update:__ it's possible to bridge enums defined in swift, by adding the `@objc` flag, and deriving from an `Int`. – Mazyod Jun 08 '15 at 09:07
  • This list is super useful and seemingly no longer available on any official Apple site... – Max Oct 21 '19 at 18:11