23

I'm trying to add Google sign in functionality to a custom button, and I'm following this tutorial. It's telling me to select the button, and set its class as GIDSignInButton, then add this code: @IBOutlet weak var signInButton: GIDSignInButton!.

However, it doesn't let me set the class to GIDSignInButton. When I type it in and press enter, the field just clears.

enter image description here

4
  • Are you sure you added the library correctly to your project? Can you use the functions/types of the library from your code? Commented Dec 24, 2017 at 11:41
  • Yes, I can use the functions. And strangely the authentication is working perfectly, even without changing the button's class for some reason.
    – sinio
    Commented Dec 24, 2017 at 11:54
  • Is it showing an option to change the Module option below Class option ?
    – Amit
    Commented Dec 24, 2017 at 14:05
  • No, Module is greyed out.
    – sinio
    Commented Dec 24, 2017 at 15:41

11 Answers 11

15

You should try assign GIDSignInButton not to the Button Object from the Object library but to the the View Object instead

It's work for me.

It will look like this using UIView instead of UIButton. enter image description here

0
12

You can create UIButton and then on its action method you can write this code for signing via google:

    GIDSignIn.sharedInstance().signIn()

It works for me, in this way you can customize UIButton according to your requirement and also perform signin by using google

0
12

That's because GIDSignInButton is a subclass of UIView, not UIButton. Add to the storyboard / nib a regular UIView and change it's class to GIDSignInButton instead.

From google doc:

Add a GIDSignInButton to your storyboard, XIB file, or instantiate it programmatically. To add the button to your storyboard or XIB file, add a View and set its custom class to GIDSignInButton.

6

GIDSignInButton can be set by using a UIView or a UIButton.

If you are using GIDSignInButton as a UIButton

  1. open the storyboard as source code
  2. Find the button in resulting XML
  3. Add the below code as an attribute for the button tag

    customClass="GIDSignInButton"

4.open storyboard again as Interface Builder, button class will be changed

If you are using GIDSignInButton as a UIView

1.copy paste the custom class as GIDSignInButton in Identity Inspector The second one is the correct approach in my opinion.

5

The workaround is open the storyboard in text mode and put it directly. When you return to the interface builder it will show normally.

1
  • This worked, thanks! However it ended up changing the styling of my button so I've left it out for now. It works perfectly without it.
    – sinio
    Commented Dec 25, 2017 at 8:57
4
  1. Open storyboard as source code.
  2. Locate the button in the xml.
  3. Set customClass="GIDSignInButton" as an attribute for the button tag.
  4. Open storyboard as interface builder.

You can now link the button to the IBOutlet

2

If you use a UIView instead of a UIButton, you can assign the view a custom class of GIDSignInButton. From there you can connect the view to a button outlet and action as seen below.

@IBOutlet weak var googleLoginButton: GIDSignInButton!

  @IBAction func googleLoginButtonPressed(_ sender: Any) {
    GIDSignIn.sharedInstance()?.signIn()
}
0
1

I had the same problem a few months ago,

Your code seems to be right

@IBOutlet weak var signInButton: GIDSignInButton!

But, the problem might be

• You haven’t added the Framework properly (Go to your project setting in the left side navigator, and click Build phases, add your framework and SHIFT + CMD + K)

• Or alternatively, go ahead and write the @IBOutlet in your swift file, then drag the button to assign it

• your last option is to close xcode, or maybe delete the derived data

Xcode itself has plenty of bugs, I am not sure if it’s your problem, it’s xcode’s

Hope this helps!

2
  • It didn't work :/ Probably an Xcode bug then, thank you for the suggestions!
    – sinio
    Commented Dec 24, 2017 at 15:53
  • No, thank you.. let me know if you need anything else Commented Dec 24, 2017 at 15:59
1

The simple way to do is just make a button action and paste the following lines in it.

   @IBAction func gSignInAction(_ sender: Any) {
         GIDSignIn.sharedInstance()?.signIn()
    }
1

Use UIView instead of UIButton and assign custom class as GIDSignInButton

0

Swift- 5

Open storyboard as source code.
Locate the button in the xml.
Set customClass="GIDSignInButton" as an attribute for the button tag.
Open storyboard as interface builder.

//MARK:- You will not find this with button XML Forcly Add this (customClass="GIDSignInButton")[![enter image description here][1]][1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.