iOS 15 Programming Fundamentals with Swift - PDF, ePUB
Скачать полную версию книги "iOS 15 Programming Fundamentals with Swift - PDF, ePUB"
In July of 2010, Chris Lattner created a folder on his computer called Shiny, and a new computer language was born. Four years later, in 2014, that language, renamed Swift, was introduced to the public, and was greeted with a mixture of surprise and excitement — and skepticism.
Prior to that moment, Cocoa programming, on iOS and before that on Mac OS, had always been done chiefly in Objective-C. The Cocoa frameworks that give an iOS app its functionality are based on Objective-C; they expect to be spoken to in Objective-C. The tradition of using Objective-C was long and deeply ingrained. For all its faults, Objective-C was the language we had learned to live with as the price of programming Cocoa. Could Cocoa be spoken to in a whole new language? Could this new language replace Objective-C as the iOS developer’s language of choice?
No one knew. I certainly didn’t know! So the first thing I did, as an experiment, was to try translating my own existing iOS apps into Swift. Not only was I able to do it, but I found the new Swift versions easier to understand and maintain than their Objective-C originals. From that moment, I was convinced that the vast majority of new iOS programmers would hitherto adopt Swift. I was right.
Swift is a superb language to learn, even (perhaps especially) if you’ve never programmed before, and is the easiest and clearest way to program iOS. It has these salient features:
Swift is a modern, object-oriented language. It is purely object-oriented: “Everything is an object.”
Swift is easy to read and easy to write. Its syntax is clear, consistent, and explicit, with few hidden shortcuts and minimal syntactic trickery.
Swift enforces strong typing to ensure that it knows, and that you know, what the type of every object reference is at every moment.
Swift is a fairly small language, providing some basic types and functionalities and no more. The rest must be provided by your code, or by libraries of code that you use — such as Cocoa.
Swift manages memory automatically. You will rarely have to concern yourself with memory management.
The Cocoa APIs are written primarily in C and Objective-C. Swift is explicitly designed to interface with most of the Cocoa APIs.
Earlier editions of this book, before 2014, taught the reader Objective-C. After 2014, they teach Swift. This edition is geared to Swift 5.5. The Swift language has reached a high state of maturity. It has achieved ABI stability, which means that the Swift language has become part of the system. Swift apps are smaller and faster than ever.
The Foundation and Cocoa APIs, however, are still written in C and Objective-C. To interact with them, you might have to know what those languages would expect. Therefore in this book I describe Objective-C in enough detail to allow you to read it when you encounter it in the documentation and on the internet, and I occasionally show some Objective-C code. Part III, on Cocoa, is largely about learning to think the way Objective-C thinks — because the structure and behavior of the Cocoa APIs are fundamentally based on Objective-C. And the book ends with an appendix that details how Swift and Objective-C communicate with one another, as well as explaining how your app can be written partly in Swift and partly in Objective-C.
- CC BY-NC-SA 3.0 PH
- Ссылка автора не требуется