1啤呼、inout定義
將值類型的對象用引用的方式傳遞”盍矗或者說地址傳遞县匠。
類似于ObjectC中的二級指針的意思
2、ObjectC中二級指針的使用
- (void)test{
NSString *name = @"name";
NSString *otherName = @"otherName";
[self getName:&name otherName:&otherName];
NSLog(@"%@ %@",name,otherName);
}
- (void)getName:(NSString **)name otherName:(NSString **)otherName{
NSLog(@"%@ %@",*name,*otherName);
*name = @"關(guān)羽";
*otherName = @"武圣";
NSLog(@"%@ %@",*name,*otherName);
}
- 打印輸出
2020-11-30 16:33:39.226129+0800 Demo[43449:375299] name otherName
2020-11-30 16:33:40.778225+0800 Demo[43449:375299] 關(guān)羽 武圣
2020-11-30 16:33:42.103776+0800 Demo[43449:375299] 關(guān)羽 武圣
3撒轮、Swift中inout的使用
func test(){
var name = "name"
var otherName = "otherName"
getName(name: &name, otherName: &otherName)
print(name,otherName)
}
func getName(name : inout String,otherName : inout String){
print(name,otherName)
name = "關(guān)羽"
otherName = "武圣"
print(name,otherName)
}
- 打印輸出
name otherName
關(guān)羽 武圣
關(guān)羽 武圣