Search code examples
objective-cswiftuiactivityviewcontrolleruiactivityios-sharesheet

Objective-C version of a custom UIActivityType


In swift, this is quite simple. For example, if I want to add a custom Pinterest UIActivityType:

extension UIActivityType {
    static let postToPinterest = UIActivityType(rawValue: "pinterest.ShareExtension")
}

This is all I have to do. However, I'm a bit confused on how to do this in objective-c. I'm thinking something like this but I'm not quite sure.

static UIActivityType UIActivityTypePostToPinterest = @"myApp.pinterest.ShareExtension";

Any help would be appreciated.


Solution

  • In Objective C, UIActivityType is just another name for NSString, so you can declare it as follows:

    // in header file
    FOUNDATION_EXPORT static NSString * const UIActivityTypePostToPinterest;
    
    // in implementation file
    FOUNDATION_EXPORT static NSString * const UIActivityTypePostToPinterest = @"myApp.pinterest.ShareExtension";
    

    Although, since Objective C isn't namespaced you should use your own prefix (like JNCActivityTypePostToPinterest instead of UI, which is reserved by Apple).