没有合适的资源?快使用搜索试试~ 我知道了~
首页Swift 2.0带你掌握面向对象编程:实战构建高效应用
Swift 2.0带你掌握面向对象编程:实战构建高效应用
需积分: 9 10 下载量 24 浏览量
更新于2024-07-20
1
收藏 25.78MB PDF 举报
"《Object Oriented Programming with Swift 2》是一本由Gastón C. Hillar编著的专业指南,专为想要学习和掌握Swift 2.0版本中面向对象编程(Object-Oriented Programming, OOP)的开发者设计。本书强调了在实际应用中理解和使用对象的重要性,通过实例演示如何将现实世界中的概念转化为易于理解且可重用的代码。 书中的主要内容包括以下几个关键知识点: 1. 认识和应用对象:作者引导读者通过生活中的实例来识别和理解对象的概念,帮助他们建立起将对象模型化并转化为代码的能力。 2. 数据封装与保护:学习如何利用Swift 2.0的数据封装特性来隐藏和保护数据,提高代码的安全性和可维护性。 3. 代码重用与泛型编程:探索如何通过编写可以处理不同类型的对象的通用代码,实现最大程度的代码复用,简化编程过程。 4. 继承与多态性:了解继承机制,包括单一继承和泛型继承,以及如何通过参数化多态来扩展和特殊化代码行为。 5. 构造函数与析构器:掌握如何根据需求自定义构造函数和析构函数,确保对象在创建和销毁时的行为符合预期。 6. 重构与源码组织:学习如何优化现有代码结构,使其更易于维护和扩展,支持iOS或Mac OS X平台的应用开发。 通过阅读这本书,读者不仅能构建出稳定、可靠的应用程序,还能提升代码质量,培养面向对象编程的最佳实践,从而构建出更强大、更可重用的代码库。同时,版权信息表明,未经许可,任何部分不得复制或传播,确保了内容的完整性和合法性。"
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/9548542/bg10.jpg)
[ v ]
Preface
Object-oriented programming, also known as OOP, is a required skill in any modern
software developer job. It makes a lot of sense because object-oriented programming
allows you to maximize code reuse and minimize maintenance costs. However,
learning object-oriented programming is challenging because it includes too
many abstract concepts that require real-life examples to be easy to understand. In
addition, object-oriented code that doesn't follow best practices can easily become a
maintenance nightmare.
Swift is a multi-paradigm programming language, and one of its most important
paradigms is OOP. If you want to create great applications and apps for Mac, iPhone,
iPad, Apple TV, and Apple Watch, you need to master OOP in Swift. In addition, as
Swift also grabs the nice features found in functional programming languages, it is
convenient to know how to mix OOP code with functional programming code.
This book will allow you to develop high-quality reusable object-oriented code in
Swift 2.2. You will learn the object-oriented programming principles and how Swift
implements them. You will learn how to capture objects from real-world elements
and create object-oriented code that represents them. You will understand Swift's
approach towards object-oriented code. You will maximize code reuse and reduce
maintenance costs. Your code will be easy to understand, and it will work with
representations of real-life elements.
What this book covers
Chapter 1, Objects from the Real World to Playground, teaches you the principles of
object-oriented paradigms. We will discuss how real-world objects can become part
of the fundamental elements of code. We will translate elements into the different
components of the object-oriented paradigm supported in Swift: classes, protocols,
properties, methods, and instances.
![](https://csdnimg.cn/release/download_crawler_static/9548542/bg11.jpg)
Preface
[ vi ]
Chapter 2, Structures, Classes, and Instances, starts generating blueprints to create
objects. You will learn about an object's life cycle, and we will work with many
examples to understand how object initializers and deinitializers work.
Chapter 3, Encapsulation of Data with Properties, introduces you to organizing data in
the blueprints that generate objects. We will understand the different members of a
class and how they are reected by members of the instances generated from a class.
You will learn the difference between mutable and immutable classes.
Chapter 4, Inheritance, Abstraction, and Specialization, introduces you to creating a
hierarchy of blueprints that generate objects. We will take advantage of inheritance
and many related features to specialize behavior.
Chapter 5, Contract Programming with Protocols, discusses how Swift works with
protocols in combination with classes. We will declare and combine multiple
blueprints to generate a single instance. We will declare protocols with different types
of requirements, and then we will create classes that conform to these protocols.
Chapter 6, Maximization of Code Reuse with Generic Code, teaches you how to maximize
code reuse by writing code capable of working with objects of different types—that
is, instances of classes that conform to specic protocols or whose class hierarchy
includes specic superclasses. We will work with protocols and generics.
Chapter 7, Object-Oriented Programming and Functional Programming, teaches you
how to refactor existing code to take full advantage of object-oriented code. We will
prepare the code for future requirements, reduce maintenance costs, and maximize
code reuse. We will also work with many functional programming features included
in Swift combined with object-oriented programming.
Chapter 8, Extending and Building Object-Oriented Code, puts together all the pieces of
the object-oriented puzzle. We will take advantage of extensions to add features to
types, classes, and protocols in which we don't have access to the source code. We
will make sure that the code exposes only the things that it has to expose, and you
will learn how everything you learned about object-oriented programming is useful
in any kind of app we might create.
What you need for this book
In order to work with Xcode and the Swift Playground, you will need a Mac OS
computer capable of running OS X 10.10.5 or later with 8 GB of RAM.
![](https://csdnimg.cn/release/download_crawler_static/9548542/bg12.jpg)
Preface
[ vii ]
In order to work with the Swift open source version on the Linux platform, you will
need any computer capable of running Ubuntu 14.04 or later or Ubuntu 15.10 or
later. These are the Linux distributions where the Swift open source binaries are built
and tested. It is also possible to run the Swift compiler and utilities on other Linux
distributions. You must take a look at the latest available documentation at the Swift
open source website, https://swift.org.
Who this book is for
If you are an IOS developer who has a basic idea of OOP and want to incorporate
OOP concepts with Swift to optimize your application's performance, then this
book is for you. This is a very useful resource for developers who want to shift from
Objective C, C#, Java, Python, JavaScript, or other object-oriented languages to Swift.
Conventions
In this book, you will nd a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, lenames, le extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as
follows: "We can assign 20 to regularHexagon1.lengthOfSide and 50 to
regularHexagon2.lengthOfSide."
A block of code is set as follows:
let degCUnitFromStr = HKUnit(fromString: "degC")
let degFUnitFromStr = HKUnit(fromString: "degF")
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
Animal created
Mammal created
DomesticMammal created
Dog created
TerrierDog created
SmoothFoxTerrier created
I am 7 years old.
I am 14 years old.
I am 21 years old.
I am 4 years old.
I am 5 years old.
![](https://csdnimg.cn/release/download_crawler_static/9548542/bg13.jpg)
Preface
[ viii ]
New terms and important words are shown in bold. Words that you see on the
screen, for example, in menus or dialog boxes, appear in the text like this: "Start
Xcode, navigate to File | New | Playground…."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail feedback@packtpub.com, and mention
the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
Downloading the example code
You can download the example code les from your account at http://www.
packtpub.com for all the Packt Publishing books you have purchased. If you
purchased this book elsewhere, you can visit http://www.packtpub.com/support
and register to have the les e-mailed directly to you.
![](https://csdnimg.cn/release/download_crawler_static/9548542/bg14.jpg)
Preface
[ ix ]
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you nd a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you nd any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are veried, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/
content/support and enter the name of the book in the search eld. The required
information will appear under the Errata section.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
Please contact us at copyright@packtpub.com with a link to the suspected pirated
material.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
eBooks, discount offers, and more
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub les available? You can upgrade to the eBook version at www.PacktPub.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at customercare@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters, and receive exclusive discounts and offers on
Packt books and eBooks.
Questions
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.
剩余331页未读,继续阅读
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/a85f9b5ddf8441b8b4d02a19e1ce0d8e_vanridin.jpg!1)
vanridin
- 粉丝: 108
- 资源: 1188
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- 解决本地连接丢失无法上网的问题
- BIOS报警声音解析:故障原因与解决方法
- 广义均值移动跟踪算法在视频目标跟踪中的应用研究
- C++Builder快捷键大全:高效编程的秘密武器
- 网页制作入门:常用代码详解
- TX2440A开发板网络远程监控系统移植教程:易搭建与通用解决方案
- WebLogic10虚拟内存配置详解与优化技巧
- C#网络编程深度解析:Socket基础与应用
- 掌握Struts1:Java MVC轻量级框架详解
- 20个必备CSS代码段提升Web开发效率
- CSS样式大全:字体、文本、列表样式详解
- Proteus元件库大全:从基础到高级组件
- 74HC08芯片:高速CMOS四输入与门详细资料
- C#获取当前路径的多种方法详解
- 修复MySQL乱码问题:设置字符集为GB2312
- C语言的诞生与演进:从汇编到系统编程的革命
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)