简体   繁体   English

无法分配给属性:“ b0”是只读属性

[英]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.3Swift 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 b0b1定义如下

    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.

相关问题 无法分配给属性&#39;observationTime&#39;是一个get-only属性 - Cannot assign to property 'observationTime' is a get-only property 无法分配给属性:&#39;inputAccessoryView&#39;是一个get-only属性 - Cannot assign to property: ‘inputAccessoryView’ is a get-only property 无法分配给属性:“ size”是仅获取属性Swift - Cannot assign to property: 'size' is a get-only property Swift 无法分配给属性:“值”是一个只能获取的属性 RxSwift - - Cannot assign to property: 'value' is a get-only property RxSwift - 无法分配给属性“tabBarController”是一个只能获取的属性 - Cannot assign to property 'tabBarController' is a get-only property 无法分配给属性:“popupHeight”是一个只能获取的属性 - Cannot assign to property: 'popupHeight' is a get-only property 无法分配给属性:“输出”是仅获取属性 - Cannot assign to property: 'outputs' is a get-only property Swift无法通过下标分配:“ peerDeviceSettings”是仅获取属性” - Swift Cannot assign through subscript: 'peerDeviceSettings' is a get-only property" 快速在键盘上方添加视图,但出现错误无法分配给属性:“ inputAccessoryView”是仅获取属性 - Swift adding view above keyboard getting Error Cannot assign to property: 'inputAccessoryView' is a get-only property 我该如何解决这个问题“无法分配给属性:'typ' 是一个只能获取的属性” - How can I solve this problem “Cannot assign to property: 'typ' is a get-only property”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM