Objective C can compile C natively. Objective C was built over C. Can swift do the same? If not what are the differences.
-
Well, the Swift compiler doesn't compile C, but you can mix C and Swift in an Xcode project and they can call each other. – vacawama Jun 11 '16 at 12:32
-
Objc is a superset of C. Swift was made to interoperate with Objc APIs including C APIs but you cannot combine C code and Swift code in one file – Sulthan Jun 11 '16 at 12:32
2 Answers
Unlike Objective-C, which is a proper superset of C, Swift has been built as an entirely new language. Swift cannot compile C code because the syntax is not compatible.
Swift can interoperate wit C code (see Interacting with C APIs article for more information). However, C code behind the APIs needs to be compiled separately, using a C compiler.

- 1
- 1

- 714,442
- 84
- 1,110
- 1,523
Swift uses swift compiler to parse and then LLVM to optimise and generate code. Hence swift compiler cannot parse C syntax.
As ObjectiveC uses clang compiler(which compiles C, C++, ObjectiveC languages) which generate syntax tree and LLVM for optimisation and code generation. Hence we can use C along with Objective C. So the Clang can parse the C/C++/objective C code, generate syntax tree, do semantic analysis and LLVM does back end compilation.

- 1,414
- 3
- 14
- 33