当前位置:首页 > 工业技术
Swift 2 面向对象编程
Swift 2 面向对象编程

Swift 2 面向对象编程PDF电子书下载

工业技术

  • 电子书积分:12 积分如何计算积分?
  • 作 者:Gaston C.Hillar著
  • 出 版 社:南京:东南大学出版社
  • 出版年份:2017
  • ISBN:9787564170790
  • 页数:309 页
图书介绍:作为一本易于操作的学习指南,本书包含了大量Swift面向对象编程常见问题的解决方法。书中以真实的场景帮助你了解对象的概念,演示如何利用对象轻松地编写出易于理解和重用的代码。你将从中学习到使用Swift的数据封装特性来保护和隐藏数据,通过编写能够处理不同类型对象的代码来最大化地实现代码重用,见识到参数多态的威力以及如何在普通代码中使用继承和多重继承。之后,你将学习重构现有代码以及使源代码易于维护和扩展的组织方法。阅读完本书之后,你将能够编写出质量更高、更健壮、更具备可重用性的代码,这一切都有助于你构建更棒的应用程序。
《Swift 2 面向对象编程》目录

Chapter 1:Objects from the Real World to Playground 1

Installing the required software 1

Capturing objects from the real world 4

Generating classes to create objects 11

Recognizing variables and constants to create properties 14

Recognizing actions to create methods 17

organizing classes with UML diagrams 20

Working with API objects in the Xcode Playground 26

Exercises 31

Test your knowledge 31

Summary 32

Chapter 2:Structures,Classes,and Instances 33

Understanding structures,classes,and instances 33

Understanding initialization and its customization 34

Understanding deinitialization and its customization 36

Understanding automatic reference counting 36

Declaring classes 37

Customizing initialization 38

Customizing deinitialization 41

Creating the instances of classes 45

Exercises 46

Test your knowledge 46

Summary 47

Chapter 3:Encapsulation of Data with Properties 49

Understanding the elements that compose a class 49

Declaring stored properties 51

Generating computed properties with setters and getters 54

Combining setters,getters,and a related property 62

Understanding property observers 65

Transforming values with setters and getters 69

Using type properties to create values shared by all the instances of a class 70

Creating mutable classes 74

Building immutable classes 78

Exercises 81

Test your knowledge 81

Summary 82

Chapter 4:Inheritance,Abstraction,and Specialization 83

Creating class hierarchies to abstract and specialize behavior 83

Understanding inheritance 88

Declaring classes that inherit from another class 90

Overriding and overloading methods 96

Overriding properties 101

Controlling whether subclasses can or cannot override members 103

Working with typecasting and polymorphism 108

Taking advantage of operator overloading 121

Declaring operator functions for specific subclasses 126

Exercises 128

Test your knowledge 128

Summary 129

Chapter 5:Contract Programming with Protocols 131

Understanding how protocols work in combination with classes 131

Declaring protocols 133

Declaring classes that adopt protocols 137

Taking advantage of the multiple inheritance of protocols 142

Combining inheritance and protocols 144

Working with methods that receive protocols as arguments 152

Downcasting with protocols and classes 155

Treating instances of a protocol type as a different subclass 159

Specifying requirements for properties 162

Specifying requirements for methods 164

Combining class inheritance with protocol inheritance 166

Exercises 178

Test your knowledge 179

Summary 180

Chapter 6:Maximization of Code Reuse with Generic Code 181

Understanding parametric polymorphism and generic code 181

Declaring a protocol to be used as a constraint 183

Declaring a class that conforms to multiple protocols 184

Declaring subclasses that inherit the conformance to protocols 188

Declaring a class that works with a constrained generic type 190

Using a generic class for multiple types 195

Combining initializer requirements in protocols with generic types 201

Declaring associated types in protocols 202

Creating shortcuts with subscripts 204

Declaring a class that works with two constrained generic types 206

Using a generic class with two generic type parameters 209

Inheriting and adding associated types in protocols 213

Generalizing existing classes with generics 214

Extending base types to conform to custom protocols 223

Test your knowledge 225

Exercises 226

Summary 227

Chapter 7:Object-Oriented Programming and Functional Programming 229

Refactoring code to take advantage of object-oriented programming 229

Understanding functions as first-class citizens 241

Working with function types within classes 243

Creating a functional version of array filtering 245

Writing equivalent closures with simplified code 247

Creating a data repository with generics and protocols 248

Filtering arrays with complex conditions 253

Using map to transform values 256

Combining map with reduce 259

Chaining filter,map,and reduce 262

Solving algorithms with reduce 262

Exercises 264

Test your knowledge 265

Summary 266

Chapter 8:Extending and Building Object-Oriented Code 267

Putting together all the pieces of the object-oriented puzzle 267

Adding methods with extensions 269

Adding computed properties to a base type with extensions 273

Declaring new convenience initializers with extensions 278

Defining subscripts with extensions 280

Working with object-oriented code in apps 281

Adding an object-oriented data repository to a project 290

Interacting with an object-oriented data repository through Picker View 294

Exercises 299

Test your knowledge 299

Summary 300

Appendix:Exercise Answers 301

Chapter 1,Objects from the Real World to Playground 301

Chapter 2,Structures,Classes,and Instances 301

Chapter 3,Encapsulation of Data with Properties 302

Chapter 4,Inheritance,Abstraction,and Specialization 302

Chapter 5,Contract Programming with Protocols 302

Chapter 6,Maximization of Code Reuse with Generic Code 302

Chapter 7,Object-Oriented Programming and Functional Programming 303

Chapter 8,Extending and Building Object-Oriented Code 303

Index 305

相关图书
作者其它书籍
返回顶部