“AppDelegate"不符合协议“GIDSignInDelegate" [英] 'AppDelegate' does not conform to protocol 'GIDSignInDelegate'

查看:64
本文介绍了“AppDelegate"不符合协议“GIDSignInDelegate"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 swift-3 中实现 Google Signin,但我遇到了一个非常奇怪的错误我正在点击链接 https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift.但是每次我一次又一次地执行它时,我都会看到这个错误.我在桥接头中添加了以下内容.

I am Trying to implement Google Signin in swift-3 but I am having a very strange error I am following the link https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift . But I see this error everytime I do Implement it again and again. I have added the following in bridging header.

#import <Google/SignIn.h>

我已经安装了 pod GoogleSignin pod 'Google/SignIn'

I have installed the pod GoogleSignin pod 'Google/SignIn'

这是我的 AppDelegate 文件代码

This is my AppDelegate File code

    class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {   //<--Here it gives the error
        //Method implemented but giving the error
        func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        //TODO
        }
    }

'AppDelegate' 不符合协议 'GIDSignInDelegate'

'AppDelegate' does not conform to protocol 'GIDSignInDelegate'

我试过重新安装 pods

I 've tried reinstalling pods

我尝试过清洁和其他事情,但没有注意到有帮助.

I've tried cleaning and other things but nope noting helped.

推荐答案

我刚刚花了 3 个小时解决这个问题.您需要实现的正确签名是:

I just spent 3 hours on this. The correct signature you need to implement is :

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)

但是 - 检查您是否没有覆盖应用中Error 的定义(或其他类GIDSignInGIDGoogleUser).我的应用程序中有一个自定义的 Error 类,它覆盖了默认的 Error 类.在我重命名我的 Error 类后,问题就消失了.

But - check whether you are not overriding the definition of Error in your app (or the other classes GIDSignIn, GIDGoogleUser). I had a custom Error class in my app which has overridden the default Error class. After I renamed my Error class, the problem went away.

Swift 编译器在这里不是很有帮助,因为它在错误消息中将两种情况的类型都显示为 Error,而没有指出它们都表示不同的 Error 类型.

Swift compiler was not very helpful here, because it displayed the type as Error for both cases in the error message, while not indicating they both mean different Error types.

教训是不要将 Foundation 中已经使用的名称用于我的课程.

The lesson is to not use names already used in Foundation for my classes.

这篇关于“AppDelegate"不符合协议“GIDSignInDelegate"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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