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

ObjC init marked NS_UNAVAILABLE is called from Swift when a 0-ary factory method is added

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:

      Description

      If I have an Objective-C class where I have an init method marked as NS_UNAVAILABLE and a factory method with no arguments and if I try to call that factory method from Swift, then the init method is invoked instead.

      Steps to Reproduce:
      Create the following Objective-C class:

      @interface SCNObject : NSObject
      + (instancetype)object;
      - (instancetype)init NS_UNAVAILABLE;
      @end
      

      From Swift do:

      _ = SCNObject()
      

      It's easy to check with the debugger that the init method is called instead of the factory method.

      If I remove the factory method, then the code won't compile and the proper error message is displayed: "'init()' is unavailable"

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            lucatorella Luca Torella
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: