当前位置:网站首页>Swift type attribute and its attentions
Swift type attribute and its attentions
2022-07-28 23:17:00 【Fluttering moth】
One 、 Type property details
Different from storage instance properties , You have to set the initial value for the storage type property
Because types don't have instances like that init Initializer to initialize storage properties
The storage type attribute defaults to lazy, It will be initialized when it is used for the first time
Even if it is accessed by multiple threads at the same time , Ensure that it is initialized only once
The storage type property can be let
Enumeration types can also define type properties ( Storage type properties 、 Calculation type properties )
Two 、 The singleton pattern
Because the type attribute has only one memory , So it can be used in the implementation of singleton .
struct Shape {
static let width: Int = 0
}
enum ShapeEnum {
static var width: Int = 0
case s1, s2, s3, s4
}
class FileManager {
public static let shared = FileManager()
private init() {
}
func open() {
}
func close() {
}
}
struct Point {
var x: Int
var y: Int
}
边栏推荐
- Thesis reading (1) - zfnet of classification
- 今年联发科5G芯片出货有望达到5000万套!
- Empowering Chinese core entrepreneurs! See how Moore elite solves the development problems of small and medium-sized chip Enterprises
- sql优化常用的几种方法
- 歌尔股份与上海泰矽微达成长期合作协议!专用SoC共促TWS耳机发展
- Wheel 6: qserialport serial port data transceiver
- Introduction to address book export without code development platform
- (important) first knowledge of C language -- function
- 《MySQL数据库进阶实战》读后感(SQL 小虚竹)
- Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
猜你喜欢

【物理应用】大气吸收损耗附matlab代码

A new paradigm of distributed deep learning programming: Global tensor

c语言进阶篇:指针(二)

Summary of common formula notes for solving problems in Higher Mathematics

Several common methods of SQL optimization

以价换量却遭遇销量“六连跌”,不再安全的沃尔沃还能翻身吗?
![[MySQL series] addition, deletion, modification and query of MySQL tables (Advanced)](/img/4c/ba2fcb6e9be2f16b73e60ab84e3f3f.png)
[MySQL series] addition, deletion, modification and query of MySQL tables (Advanced)

frontiers出版社投稿记录(附状态变化)

Cglib create proxy

Retrofit Usage Summary
随机推荐
[mongodb] basic use of mongodb database, special cases, and the installation and creation process of mongoose (including the installation of mongoose fixed version)
Invest 145billion euros! EU 17 countries announce joint development of semiconductor technology
Recurrent neural network (RNN)
A new paradigm of distributed deep learning programming: Global tensor
Introduction to original code, inverse code and complement code
Target detection notes -yolo
Improvement 16 of yolov5: replace backbone network C3 with lightweight network pp-lcnet
DirectX修复工具下载(exagear模拟器数据包在哪里)
Thesis reading (0) - alexnet of classification
Date time functions commonly used in MySQL
cannot resize variables that require grad
Retrofit Usage Summary
[C language] implementation of three piece chess games
[database]
Shell script foundation - shell operation principle + variable and array definitions
[filter tracking] target tracking based on EKF, TDOA and frequency difference positioning with matlab code
leetcode101. 对称二叉树
Learning experience sharing 3: yolov5 training data set path index
Kotlin function nesting
(important) first knowledge of C language -- function