Uploaded image for project: 'Swift'
  1. Swift
  2. SR-6399

Compilation failures on linux when adding `@objc` annotations to types that bridge to ObjC classes

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: None
    • Labels:
      None
    • Environment:

      When on mac:

      Mac OS 10.12.6
      Xcode 9.1 with default toolchain

      When on linux:

      Ubuntu 16.04
      Swift 4.0.2

      Description

      If you have some swift code that exports properties or functions to objc using the @objc annotation, and those properties or functions reference types that automatically bridge to foundation object types like NSString/NSDictionary/etc, the code will compile on macOS successfully but will fail to compile on linux.

      Some simple example code:

      import Foundation
      public class Thing: NSObject {
          @objc public init(name: String) {}
      }
      

      This compiles just fine on mac, but gives these errors/notes on linux:

      error: method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C
          @objc public init(name: String) {}
                       ^
      note: Swift structs cannot be represented in Objective-C
          @objc public init(name: String) {}
                                  ^~~~~~
      

      The same thing happens for properties where the type is inferred to be something like String. This is problematic since I'd love to be able to run the same library on Linux that we run on iOS, in order to develop integration testing tools that verify that changes to the server do not negatively impact existing customers of our iOS apps. The code in question is compiled in swift 4 mode, which means we need to provide these annotations for the obj-c code in our codebase.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              kevlario Kevin Lundberg
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: