- 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.
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- 華為HMS生態與應用開發實戰
- JIRA 7 Administration Cookbook(Second Edition)
- Reactive Programming with Swift
- Java從入門到精通(第4版)
- Django:Web Development with Python
- 你不知道的JavaScript(中卷)
- Python數據結構與算法(視頻教學版)
- Python極簡講義:一本書入門數據分析與機器學習
- C#開發案例精粹
- 動手學數據結構與算法
- C# Multithreaded and Parallel Programming
- Web App Testing Using Knockout.JS
- 算法圖解
- Java程序設計基礎(第6版)