简体   繁体   English

在Swift中声明Objective-C方法的问题

[英]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.

相关问题 将Objective-C方法转换为快速[updateSearchResultsForSearchController] - Converting objective-c method to swift [updateSearchResultsForSearchController] 迅速调用Objective-C类方法 - call objective-c class method in swift 使用Swift 3调用Objective-C方法 - Calling a Objective-C method using Swift 3 在Objective-c中等效于Swift Public方法吗? - Equivalent of a Swift Public method in Objective-c? Swift中不可见的Objective-C协议方法 - Objective-C protocol method invisible in Swift 在 Swift 中覆盖 Objective-C 类方法 - Override Objective-C class method in Swift Objective-C方法与可选的需求方法Swift冲突 - Objective-C method conflicts with optional requirement method Swift Swift 2,使用Objective-C选择器'setOn:'的方法'setOn'与使用相同Objective-C选择器的'on'的setter冲突 - Swift 2, method 'setOn' with Objective-C selector 'setOn:' conflicts with setter for 'on' with the same Objective-C selector Swift-具有Objective-C选择器'*'的方法'*()'与具有相同Objective-C选择器的超类'UIView'中的'*'的getter发生冲突 - Swift - Method '*()' with Objective-C selector '*' conflicts with getter for '*' from superclass 'UIView' with the same Objective-C selector Swift - 使用Objective-C选择器'*'的方法'*()'与来自超类'NSObject'的'*'的getter冲突,具有相同的Objective-C选择器 - Swift - Method '*()' with Objective-C selector '*' conflicts with getter for '*' from superclass 'NSObject' with the same Objective-C selector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM