Tutorial by Examples

In the same module Inside a module named "MyModule", Xcode generates a header named MyModule-Swift.h which exposes public Swift classes to Objective-C. Import this header in order to use the Swift classes: // MySwiftClass.swift in MyApp import Foundation // The class must be `public`...
If MyFramework contains Objective-C classes in its public headers (and the umbrella header), then import MyFramework is all that's necessary to use them from Swift. Bridging headers A bridging header makes additional Objective-C and C declarations visible to Swift code. When adding project files, ...
The -import-objc-header flag specifies a header for swiftc to import: // defs.h struct Color { int red, green, blue; }; #define MAX_VALUE 255 // demo.swift extension Color: CustomStringConvertible { // extension on a C struct public var description: String { return &q...
A module map can simply import mymodule by configuring it to read C header files and make them appear as Swift functions. Place a file named module.modulemap inside a directory named mymodule: Inside the module map file: // mymodule/module.modulemap module mymodule { header "defs.h&q...
When an API is marked with NS_REFINED_FOR_SWIFT, it will be prefixed with two underscores (__) when imported to Swift: @interface MyClass : NSObject - (NSInteger)indexOfObject:(id)obj NS_REFINED_FOR_SWIFT; @end The generated interface looks like this: public class MyClass : NSObject { publ...
Swift's C interoperability allows you to use functions and types from the C standard library. On Linux, the C standard library is exposed via the Glibc module; on Apple platforms it's called Darwin. #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin #elseif os(Linux) import Glibc...

Page 1 of 1