随笔分类 - Swift
摘要:前言 在学习SwiftUI所有的地方,视图元素都定义一个struct并实现View协议,该协议定义body变量返回View类型。 但是为什么,这里一直是指定的struct, 而不是class呢? 尝试使用class 如果你使用class 在SwiftUI中定义一个View,那么你将遇到一个编译器的错
阅读全文
摘要:一、代码示例 // // ViewController.swift // LazyTest // // Created by lilun.ios on 2021/7/30. // import UIKit class ViewController: UIViewController { lazy v
阅读全文
摘要:一、示例代码 import UIKit let obj = TestObj() class TestObj { init() { print("\(type(of: self)) init") } } class ViewController: UIViewController { func tes
阅读全文
摘要:示范代码 ` func testScenarioA2() throws { var store: Int = 100 DispatchQueue.concurrentPerform(iterations: 1_000_000) { _ in store.negate() _ = store } }
阅读全文
摘要:结构体并不代表线程安全,swift在此上未做保证 func testScenarioA() throws { var store: Int = 0 DispatchQueue.concurrentPerform(iterations: 1_000_000) { i in store = i _ =
阅读全文