- Swift 4 Protocol-Oriented Programming(Third Edition)
- Jon Hoffman
- 231字
- 2021-07-08 09:42:38
Classes
In object-oriented programming, we cannot create an object without a blueprint that tells the application what properties and methods to expect from the object. In most object- oriented languages, this blueprint comes in the form of a class. A class is a construct that allows us to encapsulate the properties, methods, and initializers of an object into a single type. Classes can also include other items, such as subscripts; however, we are going to focus on the basic items that make up classes not only in Swift, but in other languages as well.
Let's look at how we would use a class in Swift:
class MyClass { var oneProperty: String init(oneProperty: String) { self.oneProperty = oneProperty } func oneFunction() { } }
An instance of a class is typically called an object. However, in Swift, structures and classes have many of the same functionalities; therefore, we will use the term instance when referring to instances of either type.
Anyone who has used object-oriented programming in the past is probably familiar with the class type. It has been the backbone of object-oriented programming since its inception.
When we create instances of the class, it is named; therefore, the class is a named type. The class type is also a reference type.
The next type we are going to look at is arguably the most important type in the Swift language: Structures.
- Hands-On C++ Game Animation Programming
- Java性能權威指南(第2版)
- 微信小程序開發(fā)解析
- SQL Server 2016數據庫應用與開發(fā)
- Serverless computing in Azure with .NET
- 蘋果的產品設計之道:創(chuàng)建優(yōu)秀產品、服務和用戶體驗的七個原則
- Mastering React
- Extreme C
- MySQL入門很輕松(微課超值版)
- HTML5+CSS3+jQuery Mobile APP與移動網站設計從入門到精通
- Everyday Data Structures
- Java Web開發(fā)實例大全(基礎卷) (軟件工程師開發(fā)大系)
- Natural Language Processing with Python Quick Start Guide
- JavaEE架構與程序設計
- C語言程序設計教程