Share
Embed
iOS Module Intro
CJ
August 17, 2022
Transcript
27 slides
-
Topics covered • #include #import • .pch • Clang Module
◦ pcm ◦ .modulemap • Swift Module ◦ .swiftmodule ◦ .swiftinterface • Umbrella header • Umbrella framework -
#import at ObjC • No need #include guard • Clang
determines if this header has been included already ◦ avoids duplicate inclusion -
#import at ObjC • Compile-time scalability ◦ N translation units
◦ M headers ◦ In each translation unit, the compiler is performing M x N work ◦ Even though most of the M headers are shared among multiple translation units • Translation unit ◦ consists of a source file after it has been processed by the C preprocessor, meaning that header files listed in #include directives are literally included -
Pre Compiled Header • .pch • Precompile that bundle of
headers into a single precompiled header (PCH file). • Then, when compiling the source files in the project, we load the PCH file first. • Drawback ◦ Every .m can access the .pch -
Clang Module • Binary .pcm • Usage ◦ @import ◦
And also #include and #import after turn module ON -
Clang Module • Problems Clang Module do NOT solve: ◦
Naming collistion in the only one namespace -
Clang Module - modulemap Defines • Umbrella Header: UIKit.h •
Sub module which needs to export: All • Linked framework: UIKit -
Umbrella Header • Umbrella: something that includes or represents a
group or range of similar things. 綜合體 (from Cambridge Dictionary) • Master header for a framework -
Umbrella Framework (by the way…) • Duplicate • Difficult for
dependency and version control • Might only suitable if all the frameworks are custom frameworks -
Swift Module • The closest analogy to C-style header files
in Swift is the .swiftmodule file • Binary format (LLVM bitcode) file that records the declarations (types, function signatures, etc.) • When you import that module from another module that you're compiling, `swiftc` loads that `.swiftmodule` file into memory so that it can typecheck in that module. • Has namespace in module -
Swift Module • Internal compiler data structures ◦ Contains Abstract
Syntax Tree(AST) ◦ Swift Intermediate Language(SIL) of framework’s public API. -
.swiftinterface • Includes the version of the compiler that produced
this interface • Also contains the subset of command line flags that the Swift Compiler needs to import this as a module. -
.swiftinterface • List all the modules that this framework imports
• Dependency graph ! -
.swiftinterface • Include the public API, but not private •
class has a de-initializer in the interface. If don't provide an explicit de-initializer, the compiler generates one -
.swiftinterface if you make an enum without any associated values,
then the compiler implicitly makes that conform to an Equitable and Hashable -
ObjC Interface of Swift Framework • Xcode's default template ◦
Objective-C Umbrella Header ◦ Generated header ▪ containing the Objective-C parts in the framework -
ObjC Interface of Swift Framework • Generated header: Framework-Swift.h ◦
containing the Objective-C parts in the framework