0

在swift中,這很簡單。例如,如果我想添加自定義Pinterest UIActivityType:Objective-C版本的自定義UIActivityType

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

這就是我所要做的。但是,我對如何在objective-c中做到這一點感到困惑。我在想這樣的事情,但我不太確定。

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

任何幫助,將不勝感激。

回答

1

在Objective C,UIActivityTypeNSString的另一個名稱而已,所以你可以聲明如下:

// in header file 
FOUNDATION_EXPORT static NSString * const UIActivityTypePostToPinterest; 

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

雖然,因爲目標C沒有命名空間,你應該使用自己的前綴(如JNCActivityTypePostToPinterest代替由蘋果公司保留的UI)。