0x00ZhouJialei 最近的时间轴更新
0x00ZhouJialei

0x00ZhouJialei

V2EX 第 447680 号会员,加入于 2019-10-18 16:01:00 +08:00
0x00ZhouJialei 最近回复了
2022-09-15 16:25:37 +08:00
回复了 Yunsheng 创建的主题 推广 🥝🥝🥝继续送猕猴桃,分子集合🥝🥝🥝
+1
2021-12-23 12:37:36 +08:00
回复了 i66 创建的主题 推广 餐饮已转让。回山村卖特产腊肉... 例行抽奖 😊
分子分子
2021-11-14 14:03:50 +08:00
回复了 rebnonu 创建的主题 推广 自家种的赣南脐橙给 V 友的福利只有 200 斤,抽奖 3 箱
分子
2021-10-26 10:50:41 +08:00
回复了 Rezark 创建的主题 推广 相约第二年,继续送苹果!
分子
2021-05-09 03:33:06 +08:00
回复了 fffang 创建的主题 iDev Swift 为什么设计 inout 关键字?
先说动机 , 引用自 https://docs.swift.org/swift-book/LanguageGuide/Functions.html In-Out Parameters 章节:
Function parameters are constants by default. Trying to change the value of a function parameter from within the body of that function results in a compile-time error. This means that you can’t change the value of a parameter by mistake. If you want a function to modify a parameter’s value, and you want those changes to persist after the function call has ended, define that parameter as an in-out parameter instead.

再说行为, 引用自 https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID545:
In-out parameters are passed as follows:
1. When the function is called, the value of the argument is copied.
2. In the body of the function, the copy is modified.
3.When the function returns, the copy’s value is assigned to the original argument.
This behavior is known as copy-in copy-out or call by value result. For example, when a computed property or a property with observers is passed as an in-out parameter, its getter is called as part of the function call and its setter is called as part of the function return.

多说几句,编译器有可能会把 inout 优化为所谓的传址(call-by-reference),但是官方特意指出开发者们不能依赖这个行为:
As an optimization, when the argument is a value stored at a physical address in memory, the same memory location is used both inside and outside the function body. The optimized behavior is known as call by reference;
Write your code using the model given by copy-in copy-out, without depending on the call-by-reference optimization, so that it behaves correctly with or without the optimization

不严谨的验证方式是,传一个带有 willSet 或者 didSet 的变量到一个 function 的 inout 参数内,就算在 function 内不改变值,willSet 或者 didSet 也会触发
2021-03-16 14:09:00 +08:00
回复了 mashaofeixxx 创建的主题 推广 NUC8i5 黑果套餐返场! 抽一人送西数黑盘.
分子来了...
2021-02-26 11:17:55 +08:00
回复了 mashaofeixxx 创建的主题 推广 回贴抽奖! 2021 NUC 黑果 下单抽牛年福袋
分母+1
2020-12-17 21:27:19 +08:00
回复了 studytogether 创建的主题 酷工作 字节跳动这个岗位一直严重缺人,面试标准重定了
@studytogether 老哥能留个联系方式吗 了解一下具体流程
2020-12-07 16:07:31 +08:00
回复了 peterzhang0602 创建的主题 macOS Too many open files in system 折磨死了
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5268 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 15ms · UTC 09:26 · PVG 17:26 · LAX 01:26 · JFK 04:26
Developed with CodeLauncher
♥ Do have faith in what you're doing.