2

While updating to Xcode 8 Beta 6, from what I saw a new type got introduced: UIActivityType

So I tried to do somewhere like this in my UIActivity custom class:

class FooActivity: UIActivity {
    func retrieveActivityType() -> String {
        return "someStringDescribingActivityType"
    }

    override open var activityType: UIActivityType? {
        @objc(retrieveActivityType)
        get {
            return UIActivityType(rawValue: "someStringDescribingActivityType")
        }
    }
}

where retrieveActivityType() is the Objective-C equivalent since UIActivityType is only defined in Swift. But no luck so far, still having two errors:

  1. Property cannot be an @objc override because its type cannot be represented in Objective-C
  2. '@objc' getter for non-'@objc' property

Is there something obvious that I'm missing?

4

1 回答 1

1

通过将返回类型设置为non-optional找到了一个快速修复。我想在 beta 7 发布之前没有真正的解决方法。

class FooActivity: UIActivity {
    override open var activityType: UIActivityType {
    get {
        return UIActivityType(rawValue: "someStringDescribingActivityType")
    }
}

资料来源:

https://bugs.swift.org/browse/SR-2344

https://github.com/apple/swift/pull/4360

于 2016-08-23T02:06:30.990 回答