![]() That said, NS_TYPED_ENUM immutability is not compiler-enforced. Despite the fact that both are structs, code that takes an NS_TYPED_ENUM will crash if we use it with a raw value not defined for the struct, but NS_EXTENSIBLE_TYPED_ENUM will handle that scenario. ![]() Why? The attributes were designed on the Clang side, but then developers took a second look at the Swift side and realized that enum wouldn’t behave the way they wanted. ![]() Regardless of their values, both are imported as Swift structs. Under the hood, NS_TYPED_EXTENSIBLE_ENUM is a Clang attribute that instructs the compiler to use the struct ( swift_wrapper(struct) attribute), while with the NS_TYPED_ENUM, the compiler is instructed to use the enum ( swift_wrapper(enum) attribute). Now you can store a block as an Any type for the Objective-C part of the codebase. We use NS_ENUM macro in Objective-C code, and this construction is automatically recognized by Swift, so it imports with the Swift enum type. In the following sections, let’s have a quick overview of what we use. In the book, you’ll find all the necessary tools to make the coexistence of Objective-C and Swift code a good experience. The tool is platform agnostic, yet there are plenty of UIKit/ AppKit-specific rules based on the Coding Guidelines for Cocoa naming conventions.Īll the rules are described in a great e-book by Apple, Using Swift with Cocoa and Objective-C. But Swift has a tremendous Objective-C importer, ClangImporter, which is used to import Objective-C (and C) code into Swift automatically. ![]() The Objective-C API in the Swift world can feel a bit awkward. This is an optional Swift extension that may be used on top of the binary framework we distribute. Today we’re introducing PSPDFKitSwift, a collection of wrappers to and extensions for the regular amework. While interoperability between Objective-C and Swift is already good, we decided to put in extra effort to make using our SDK from Swift a first-class experience, matching what Apple provides with its frameworks. Our main SDK is written in Objective-C, but we can’t yet switch our SDK to Swift, both because we still have many customers using Objective-C, and because Swift does not yet have a stable ABI. At PSPDFKit, we use Swift in almost all our projects.
0 Comments
Leave a Reply. |