[英]Cannot assign to property: 'b0' is a get-only property
Let me preface with this, I have very little understanding of swift (was just passed this project yesterday). 让我以此开头,我对swift知之甚少(昨天刚刚通过了这个项目)。 I'm trying to reproduce the build in Xcode8.3.3
and Swift 3.1
我正在尝试在Xcode8.3.3
和Swift 3.1
重现该版本
I've fixed a few compile sources issues and some other class related errors. 我已经修复了一些编译源问题以及其他一些与类相关的错误。 I ran into a get-only property error. 我遇到了仅获取属性错误。
var cloudUse : F2Type32 = 0x1;
var anyCloudUse : Bool {
get {
return (cloudUse != 0) ? true : false
}
}
var iCloudUse : Bool {
get {
return cloudUse.b0
}
set(newValue) {
cloudUse.b0 = newValue //error. Cannot assign to property: 'b0' is a get-only property
}
}
var googleDriveUse : Bool {
get {
return cloudUse.b1
}
set(newValue) {
cloudUse.b1 = newValue //error. Same as above
}
}
I looked at this get-only property . 我看着这个get-only属性 。 But still can't seem to figure out what's going on. 但是似乎仍然无法弄清楚到底发生了什么。
b0
and b1
are defined below b0
和b1
定义如下
extension VInt {
func maxSize() -> UIntMax { return self.asU64 }
init(_ val : Int) {
if (val > 0) {self.init(UIntMax(val)) }
else {
self.init(UIntMax(val&0x7fffffff)) } }
init(fromMax : UIntMax) { self.init(fromMax) }
init<T2 : VInt>( val : T2) { self.init(fromMax : val.asMaxSize) }
var b0 : Bool {
return ((self & 0x1) == 0) ? false : true}
var b1 : Bool {
return ((self & 0x2) == 0) ? false : true}
Here's my first attempt at a fix. 这是我第一次尝试修复。 The extension currently only has a getter, so we'll edit that extension to replace the lines to something like this: 该扩展名当前只有一个吸气剂,因此我们将编辑该扩展名以将行替换为以下内容:
var b0 : Bool {
get {return ((self & 0x1) == 0) ? false : true}
set {self = newValue ? self & 0x1 : self ^ 0x1}
}
var b1 : Bool {
get {return ((self & 0x2) == 0) ? false : true}
set {self = newValue ? self | 0x2 : self ^ 0x2}
}
Hopefully I got the bitset stuff right (it's not my strong suit). 希望我能正确解决这个问题(这不是我的强项)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.