1

When I build java object class in a project, build file will be created with .class extension and human unreadable; What about swift build files?

example:

car.java  --> build --> car.class

what would be after build?

car.swift --> build --> ?
Dávid Pásztor
  • 40,247
  • 8
  • 59
  • 80
BatyrCan
  • 4,077
  • 2
  • 11
  • 21
  • I think you are interested in this article: https://www.bignerdranch.com/blog/manual-swift-understanding-the-swift-objective-c-build-pipeline/ – Dominik Bucher Oct 11 '18 at 09:55

3 Answers3

3

The compilation process is a bit different with Swift to Java, so there isn't necessarily a direct equivalent.

As the build proceeds though each Swift file will get compiled in to an 'Object' file, ending in a .o extension. Then once they're all built they get linked together to form the binary. If you unpick an iOS app's IPA file, you won't see the individual .o files like how you can see the .class files inside a Java jar file.

3

One thing I know is that Swift uses LLVM just like Objective-C.

So in Java, we have this (source: W3schools). enter image description here

And here, for Swift (source: Swift.org)

enter image description here

I hope this helps!

Glenn Posadas
  • 10,706
  • 4
  • 36
  • 75
2

Mach-O format

[LLVM]

In iOS world every sources file - .m, .h, .swift are compiled into executable byte code that is understandable by CPU. These files are also called Mach object(.o) - ABI Mach-O[About] file which contains nexts grouped bytes with a meta-information

  • Mach-O header - general information like cpu type(CPU_TYPE)
  • Load Commands - table of contents
  • Raw segment data - code

This groups are repeated for every architecture(Universal library)[About]

`*.swift` -> `*.o` (Mach-O object file)

For example if you created a static library - myLibrary.a. You can use nm[About] command to display name list (symbol table).

nm path/myLibrary.a

As a result you will see a list of *.o files with methods, variables names etc.

To investigate Mach-O file you can use otool[About]

[Mach-O Type]

[Xcode build process]

yoAlex5
  • 13,571
  • 5
  • 105
  • 98