Appendix. C, Objective-C, and Swift

The APIs for Cocoa and its associated frameworks are written in Objective-C or its underlying base language, C. Messages that you send to Cocoa using Swift are being translated for you into Objective-C. Objects that you send and receive back and forth across the Swift/Objective-C bridge are Objective-C objects. Some objects that you send from Swift to Objective-C are even being translated for you into other object types, or into nonobject types.

This appendix summarizes the relevant linguistic features of C and Objective-C, and describes how Swift interfaces with those features. I do not explain here how to write Objective-C! For example, I’ll talk about Objective-C methods and method declarations, because you need to know how to call an Objective-C method from Swift; but I’m not going to explain how to call an Objective-C method using Objective-C.

The C Language

C provides the linguistic underpinnings of Objective-C. Objective-C is a superset of C; everything that is true of C is true also of Objective-C. It is possible, and often necessary, to write long stretches of Objective-C code that are, in effect, pure C. Some of the Cocoa APIs are written in C. Therefore, in order to know about Objective-C, it is necessary to know about C.

The C language was evolved during the early 1970s at Bell Labs in conjunction with the creation of Unix. The reference manual, The C Language by Brian Kernighan and Dennis M. Ritchie, was published in 1978, and ...

Get iOS 15 Programming Fundamentals with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.