xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Swift private(set) All In One

Swift private(set) All In One

SwiftUI

Getters and Setters

https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html#ID18

public private(set)

SDK


struct TrackedString {
    // private(set) 对内可修改, 对外可见
    private(set) var numberOfEdits = 0
    var value: String = "" {
        didSet {
            numberOfEdits += 1
        }
    }
}


public private(set)


public struct Counter {
    // I specify that only the setter is private!
    public private(set) var count: Int
}

https://www.natashatherobot.com/swift-magic-public-getter-private-setter/

private(set) === closure



struct Person {
  // private(set) 对外只读,对内可写
  private(set) var name: String = "xgqfrms"
  // func getName() {
  //   return self.name;
  // }
  func setName(name: String) {
    return self.name = name;
  }
  // public let age: Int = 18
  private var age: Int = 18
  // 闭包 closure, 对内开放,对外关闭
  func getAge() {
    return self.age;
  }
  func setAge(name: Int) {
    return self.age = age;
  }
}


refs

https://www.youtube.com/watch?v=4GjXq2Sr55Q&ab_channel=Stanford

https://www.tryswift.co/

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-11-03 10:43  xgqfrms  阅读(1826)  评论(4编辑  收藏  举报