ios - 在函数中使用多个 inout 参数时应用程序崩溃

标签 ios swift3 inout

当我使用下面的代码时,我的应用程序崩溃了。

var char : Character = "1"
var char2 : Character = "1"

func changeChar( char1: inout Character,char2: inout Character) {
    char = "b"
    char2 = "b"
}

override func viewDidAppear(_ animated: Bool) {
    print(char,char2)
    changeChar(char1: &char, char2: &char2)
    print(char,char2)
} 

错误:

Simultaneous accesses to 0x100e0ec50, but modification requires exclusive access.
Previous access (a modification) started at PPlayerNew`ViewController.viewDidAppear(_:) + 340 (0x1000eeda8).
Current access (a modification) started at:
0    libswiftCore.dylib                 0x00000001004b9a38 swift_beginAccess + 468
1    PPlayerNew                         0x00000001000ee960 ViewController.char.setter + 92
2    PPlayerNew                         0x00000001000eebbc ViewController.changeChar(char1:char2:) + 96
3    PPlayerNew                         0x00000001000eec54 ViewController.viewDidAppear(_:) + 436
4    PPlayerNew                         0x00000001000eef98 @objc ViewController.viewDidAppear(_:) + 64
5    UIKit                              0x000000018b3cc5c0 <redacted> + 856
6    UIKit                              0x000000018b439630 <redacted> + 44
7    UIKit                              0x000000018b43959c <redacted> + 92
8    UIKit                              0x000000018b641470 <redacted> + 556
9    UIKit                              0x000000018b633420 <redacted> + 528
10   UIKit                              0x000000018b64c7b4 <redacted> + 152
11   CoreFoundation                     0x00000001852312f8 <redacted> + 20
12   CoreFoundation                     0x0000000185230a08 <redacted> + 288
13   CoreFoundation                     0x000000018522e6c0 <redacted> + 728
14   CoreFoundation                     0x000000018515ebfc CFRunLoopRunSpecific + 424
15   GraphicsServices                   0x0000000186bc9010 GSEventRunModal + 100
16   UIKit                              0x000000018b419bcc UIApplicationMain + 208
17   PPlayerNew                         0x00000001000f0570 main + 76
18   libdyld.dylib                      0x000000018416d598 <redacted> + 4

但是当我使用单个参数函数时,如下所示。代码正在运行

func changeChar( char1: inout Character) {
    char = "b"        
}

所以我的主要目标是使用带多个参数的 inout 函数。我该怎么做或者我的代码有什么问题?

谢谢。

最佳答案

您正在更改 func 中的属性 char 而不是参数 char1。

关于ios - 在函数中使用多个 inout 参数时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49526393/

相关文章:

swift - swift 3 中的核心数据轻量级迁移不起作用

ios - 将 SKNode 从其当前位置移动一个 Tile

ios - Google Chromecast list 内字幕

ios - Swift:通过单击按钮修改数据格式

ios - 表格单元格中的动画约束更改

MySQL 存储过程参数

verilog - 如何写入 inout 端口并从同一模块的 inout 端口读取?

ios - 如何在 Objective-C 中从 HTML 读取 JSON-LD 数据?

swift - AVCaptureSession Swift 3 执行错误问题?

swift - 允许 inout 参数使用默认值