Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Swift中为引用的C结构中的属性设置值_Swift - Fatal编程技术网

在Swift中为引用的C结构中的属性设置值

在Swift中为引用的C结构中的属性设置值,swift,Swift,我想做的是修改我有引用的C结构的值,如下所示: 在bridgengheader.h中: struct info_type { int priority; }; 在ViewController.swift中: class MyClass { func viewDidLoad() { var info = info_type() info.priority = 2 processInfo(&info) }

我想做的是修改我有引用的C结构的值,如下所示:

在bridgengheader.h中:

struct info_type {
    int priority;
};
在ViewController.swift中:

class MyClass {
    func viewDidLoad() {
        var info = info_type()
        info.priority = 2    
        processInfo(&info)
    }

    func processInfo(infoRef: UnsafePointer<info_type>) {
        info.memory.priority = 1
    }
}

我是做错了什么,还是偶然发现了Xcode错误?我使用的是Xcode 7.0 beta 2(版本7.0 beta(7A121l))

,因为
processInfo()
方法修改指向的内存 通过
infoRef
,必须将参数声明为可变指针:

func processInfo(infoRef:UnsafeMutablePointer){
infoRef.memory.priority=1
}
这将按照预期进行编译和工作

Xcode 6.4为您的代码发出正确的错误消息:

func processInfo(infoRef: UnsafePointer<info_type>) {
    infoRef.memory.priority = 1 // error: cannot assign to the result of this expression
}
func processInfo(infoRef:UnsafePointer){
infoRef.memory.priority=1//错误:无法分配到此表达式的结果
}
但是Xcode 7 beta 2崩溃,这是一个bug

func processInfo(infoRef: UnsafeMutablePointer<info_type>) {
    infoRef.memory.priority = 1
}
func processInfo(infoRef: UnsafePointer<info_type>) {
    infoRef.memory.priority = 1 // error: cannot assign to the result of this expression
}