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?

gabuchan
  • 785
  • 1
  • 7
  • 18
  • If the type only exists in Swift, defining a different name for the getter doesn't help. – Avi Aug 22 '16 at 10:45
  • Aside: if `UIActivityType` is not a `UIKit` type, I recommend renaming it. It's confusing. – Avi Aug 22 '16 at 10:45
  • This is an issue if you are simply extending the class `UIActivityItemProvider` and overriding any of the `UIActivityItemSource` protocol methods (specifically the one that provides the subject for the activity type). The error is: "Method cannot be an @objc override because the type of the parameter 2 cannot be represented in Objective-C" – lotz Aug 26 '16 at 02:25

1 Answers1

1

Found a quick fix by just making the return type as non-optional. I guess there is no real workaround until beta 7 gets released.

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

Sources:

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

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

gabuchan
  • 785
  • 1
  • 7
  • 18