我一直在尋找爲什麼Objective-C類中的singleton方法定義在Xcode的Swift接口上不可用的原因的文檔。Objective C Singleton方法不適用於Swift接口
的Objective-C類的定義如下
/**
* A general accessor across the sample App to remove the dependency of QPSLibraryManager from resusable components.
*/
@interface QPSSharedAccessor : NSObject
/**
* Required by QPSLibraryManager and some UI components.
*/
@property (nonatomic, strong) QPSApplicationConfiguration *qpsConfiguration;
/**
* Provides Commands to app
*/
@property (nonatomic, strong) id<QPSAppController> appController;;
/**
* Shared singleton.
*/
+ (instancetype)sharedAccessor;
/**
* Returns access to a configuration manager
*/
- (QPSConfigurationManager *)configurationManager;
@end
在夫特接口,其像這樣
/**
* A general accessor across the sample App to remove the dependency of QPSLibraryManager from resusable components.
*/
open class QPSSharedAccessor : NSObject {
/**
* Required by QPSLibraryManager and some UI components.
*/
open var qpsConfiguration: QPSApplicationConfiguration!
/**
* Provides Commands to app
*/
open var appController: QPSAppController!
/**
* Returns access to a configuration manager
*/
open func configurationManager() -> QPSConfigurationManager!
}
定義我期望看到的sharedAccessor()單方法上夫特但正如你所看到的那樣,它缺失了。在單獨的swift文件中調用該方法會導致編譯器錯誤,並說sharedAccessor()方法不存在。把所有東西都轉換成Swift是不可行的。建議解決這個問題?