当我使用下面的代码时,我的应用程序崩溃。
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
但是当我使用单个param函数时,如下所示。代码正在运行
func changeChar( char1: inout Character) {
char = "b"
}
所以我的主要目标是使用带有多个参数的inout函数。我怎么能这样做或者我的代码有什么问题?
谢谢。
答案 0 :(得分:1)
您正在更改func中的属性char而不是参数char1。