Objective-C方法与可选的需求方法Swift冲突 [英] Objective-C method conflicts with optional requirement method Swift

查看:157
本文介绍了Objective-C方法与可选的需求方法Swift冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode更新后,编译器开始在工作代码上抛出错误(两个函数都在AppDelegate.swift中)。

After the Xcode update, the compiler began to throw an error on the working code (both functions are in the AppDelegate.swift).

func application(application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool 
{
    FBLoginView.self
    FBProfilePictureView.self
    return true
}

错误:


/ Users /../ AppDelegate.swift:14:11:Objective -C方法'application:didFinishLaunchingWithOptions:'由方法'application(:didFinishLaunchingWithOptions :)提供'与协议'UIApplicationDelegate'中的可选需求方法'application(:didFinishLaunchingWithOptions :)'冲突

/Users/../AppDelegate.swift:14:11: Objective-C method 'application:didFinishLaunchingWithOptions:' provided by method 'application(:didFinishLaunchingWithOptions:)' conflicts with optional requirement method 'application(:didFinishLaunchingWithOptions:)' in protocol 'UIApplicationDelegate'

第二个

func application(application: UIApplication,        
                            openURL url: NSURL,
                            sourceApplication: NSString?,
                            annotation: AnyObject) -> Bool {
    var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication as! String)
    return wasHandled
}

有错误


/ Users /../ AppDelegate.swift:25: 11:Objective-C方法
'应用程序:openURL:sourceApplication:annotation:'由方法提供'应用程序(:openURL:sourceApplication:annotation :)'与可选的需求方法'应用程序冲突( :openURL:sourceApplication:annotation :)'in protocol'UIApplicationDelegate'

/Users/../AppDelegate.swift:25:11: Objective-C method 'application:openURL:sourceApplication:annotation:' provided by method 'application(:openURL:sourceApplication:annotation:)' conflicts with optional requirement method 'application(:openURL:sourceApplication:annotation:)' in protocol 'UIApplicationDelegate'

我明白我很可能希望你能以某种方式粘在一起这两个功能合而为一。我不明白为什么这个代码在6.3中突然停止工作,尽管它在6.2中工作。

I understand that most likely I should like you to stick together somehow these two functions into one. I do not understand why this code suddenly stopped working in 6.3, despite the fact that it worked in 6.2.

推荐答案

我是不确定为什么编译器会抛出错误,但我确实看到这些相同方法的默认Swift版本有所不同。也许你可以用普通的Swift项目替换函数声明:

I'm not sure exactly why the compiler is throwing the error, however I do see a difference in the default Swift version of those same methods. Perhaps you could replace the function declaration with those created with a normal Swift project:

func application(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool

func application(application: UIApplication,openURL url:NSURL,sourceApplication:String?,annotation:AnyObject) - > Bool

我建议用上面的方法替换你的方法声明,看它现在是否编译。

I'd recommend replacing your method declarations with the above to see if it compiles now.

编辑1(2015年9月21日):我已经确认这些是Xcode 7公开发布的最新版本。他们删除了可选(注释:AnyObject?)并在声明#2中创建了它(注释:AnyObject )。

EDIT 1 (9/21/2015): I've confirmed these are now up to date for Xcode 7's public release. They removed the optional (annotation: AnyObject?) and made it (annotation: AnyObject), in declaration #2.

这篇关于Objective-C方法与可选的需求方法Swift冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆