Conforming to protocol - adding protocol stubs again and again doesn't fix the error

1k views Asked by At

So I have class FBViewController which should show a button log me in and log out (just to test FB login). I integrated this in newly created project and all worked. Then I reworked it into my app and it's not working. Not sure if it has something to do with swift version or sth else... Using Xcode 10.0

import UIKit
import FBSDKLoginKit

class FBViewController: UIViewController, FBSDKLoginButtonDelegate {


    override func viewDidLoad() {
        super.viewDidLoad()
        let btnFBLogin = FBSDKLoginButton()
        btnFBLogin.readPermissions = ["public_profile", "email"]
        btnFBLogin.delegate = self
        btnFBLogin.center = self.view.center
        self.view.addSubview(btnFBLogin)

        if FBSDKAccessToken.current() != nil{
            print("Logged IN ALREADY")
            printInfo()
        }else{
            print("not logged in")
        }

    }

    func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
        if error != nil{
            print(" error")
      //      print(error.localizedDescription)
        }else if result.isCancelled {
            print("User cancelled.")
        }
        else {
            print("Logge IN!")
            printInfo()
        }
    }

    func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
        print("logged out")
    }

    func printInfo(){


        if(FBSDKAccessToken.current() != nil){

            FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id,name , first_name, last_name , email"]).start(completionHandler: { (connection, result, error) in

                guard let Info = result as? [String: Any] else { return }

                if let userName = Info["name"] as? String
                {
                    print(userName)
                }

            })
        }
    }

}

FBSDKLoginButtonDelegate

/**
 @protocol
  A delegate for `FBSDKLoginButton`
 */
@protocol FBSDKLoginButtonDelegate <NSObject>

@required
/**
  Sent to the delegate when the button was used to login.
 @param loginButton the sender
 @param result The results of the login
 @param error The error (if any) from the login
 */
- (void)loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
                error:(NSError *)error;

/**
  Sent to the delegate when the button was used to logout.
 @param loginButton The button that was clicked.
*/
- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton;

@optional
/**
  Sent to the delegate when the button is about to login.
 @param loginButton the sender
 @return YES if the login should be allowed to proceed, NO otherwise
 */
- (BOOL) loginButtonWillLogin:(FBSDKLoginButton *)loginButton;

@end

Adding protocol stubs adds just 1 function (loginButton...) which is already implemented and it seems like it doesn't recognize it.

https://i.stack.imgur.com/O7EZ0.png

I tried cleaning project, removing derived data, restarting but still, it keeps giving me the same error:

Type 'FBViewController' does not conform to protocol 'FBSDKLoginButtonDelegate'

Help appreciated! Thanks

3

There are 3 answers

2
mentoxska On BEST ANSWER

So after a lot of searching I have found out an answer to this problem which is described here

I have imported Turbolinks-ios which had its own Error struct, I had to use Swift.Error in method stub -

 func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Swift.Error!) {...
1
Romulo BM On

Try to uninstall and reinstall the pods doing the following steps:

Remove all the dependencies from your .podfile (or just comment by adding a # at the beginning of the line ) Run pod install on your project directory and waiting for uninstall all pods removed re-add the pods dependencies and run pod install again Clean your project e build again


Plus: sometimes i got similar problems that are solved simply removing the functions that are required e already implemented, and try to re-adding using the auto-complete of the Xcode.

For exemple, start typing the method, choose the right on auto-complete list(if doesn't appear use ^+Space), and press enter: sample

0
Tiago Mendes On

For others who may have come here to have problems with a class Delegate from Cocoapod.

So the issue that was having I was adding the protocols

func photo(captured: UIImage?, currentStep: StepEnum) {

But they were always asking to repeat because the cocoapod project and my project had the same class name "StepEnum" to fix that I just had to change my class name and it was resolved.