Swift doesn't support extending CoreGraphics types

Originator:jlieske
Number:rdar://17743905 Date Originated:20-Jul-2014 11:10 PM
Status:Closed Resolved:Fixed in Xcode 6 Beta 5
Product:Developer Tools Product Version:Xcode 6 beta 3: Version 6.0 (6A254o)
Classification:Other Bug Reproducible:Always
 
One of the best features of Swift is that named types can be extended with new methods.  This encourages a development style that builds up libraries incrementally for expressive programs.

However, the types bridged from CoreGraphics such as CGContext are an exception.  The compiler accepts extensions to CoreGraphics types, but the linker fails to link the program.

This is the essence of the code the exhibits the issue in Beta 3.

import Foundation
import CoreGraphics

extension CGContext {
    func fillRect(rect: CGRect) {
        CGContextFillRect(self, rect)
    }
}

The error in the Beta 3 linker is:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_CGContext", referenced from:
      l__CATEGORY_CGContext_$_TryCoreGraphics in main.o
ld: symbol(s) not found for architecture x86_64

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!