Understanding the Swift Build Pipeline

How swift works without header file or include files?

Understanding the Swift Build Pipeline

How swift works without header file or include files?

I was curious about how swift manages all the things without using header files, include header files…and finally i read things about it , let me share with you.

Obj-C compilation relies on headers and object files. Swift doesn’t use headers, and you’ve probably never run into a Swift object file, either. How does Xcode solve this?

By generating a header and object file per Swift file, of course!

Each Swift file gets compiled into an object file and, for use from Obj-C, a header file: A.swift -> A.o, A.h

Yup — the Swift files themselves are effectively header files!

Importing names from other files in a module is implicit in the source code: you can freely use a type B defined in B.swift while you’re writing code in A.swift, and you just expect it to be available. If this were Obj-C, it’d be roughly like every .m file in your project automagically gained a series of #imports of every .h file in your project.

Swift code does not have #imports to name the specific files to factor into compilation of a single .swift file, though. So instead of listing all the files in the module in the .swiftfile, that list moves to the compiler invocation: When you compile a single Swift file, the compiler invocation lists every other Swift file in that module.

Good thing Xcode is writing those compiler invocations for you, yeah?

Hope you like this article & is useful for people looking to find out the answer, Please ❤️ to recommend this post to others 😊. Let me know your feedback. :)

References:

  1. https://www.bignerdranch.com/blog/manual-swift-understanding-the-swift-objective-c-build-pipeline/