[英]Issue in declaring an objective-C method in Swift
I am trying to use FCOfflineQueue (a persistent framework for queuing network requests while offline) with my iOS app written in Swift. 我正在尝试将FCOfflineQueue(一种用于在脱机时对网络请求进行排队的持久框架)与以Swift编写的iOS应用一起使用。 I am supposed to subclass the FCOfflineQueue
class and override the following method in my subclass- 我应该对FCOfflineQueue
类进行子类化,并在我的子类中重写以下方法-
- (BOOL)executeOperation:(int64_t)opcode userInfo:(NSDictionary *)userInfo;
In my own queue that I subclassed from FCOfflineQueue
, am having trouble declaring this in Swift. 在我自己从FCOfflineQueue
子类化的队列中,很难在Swift中进行声明。 I am doing the following- 我正在做以下事情-
override func executeOperation(opcode: Int64, userInfo: NSDictionary) -> Bool
It says- this method does not override any method from its superclass. 它说-此方法不会覆盖其超类中的任何方法。
If instead I do the following- 如果相反,我将执行以下操作-
@objc override func executeOperation(opcode: Int64, userInfo: NSDictionary) -> Bool
It says- Overriding method with selector 'executeOperation:userInfo:' has incompatible type '(Int64, NSDictionary) -> Bool' 它说-具有选择器'executeOperation:userInfo:'的重写方法具有不兼容的类型'(Int64,NSDictionary)-> Bool'
I thought int64_t
is equivalent to Int64
in Swift. 我以为int64_t
相当于Swift中的Int64
。 Is it something to do with the conversion? 与转换有关吗?
Any help is appreciated. 任何帮助表示赞赏。
try to override like this: 尝试像这样覆盖:
override func executeOperation(opcode: Int64, userInfo: [NSObject : AnyObject]!) -> Bool {
return false
}
When you bridge from an NSDictionary object with parameterized types to a Swift dictionary, the resulting dictionary is of type [ObjectType]. 当您将具有参数化类型的NSDictionary对象桥接到Swift字典时,所得字典的类型为[ObjectType]。 If an NSDictionary object does not specify parameterized types, it is bridged to a Swift dictionary of type [NSObject: AnyObject]. 如果NSDictionary对象未指定参数化类型,则将其桥接到[NSObject:AnyObject]类型的Swift字典中。
https://developer.apple.com/library/mac/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html https://developer.apple.com/library/mac/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.