May 29, 2016: The class name in the selector may be removed. Use #selector(buttonPressed) instead of #selector(ViewController.buttonPressed) for code simplicity. On March 21, 2016, Apple released Xcode 7.3 with Swift 2.2. This new version of Swift is the first official release after the programming language became open source on December 3, 2015. The official Swift.org blog says that 212 non-Apple programmers have contributed to this release. Below is the first issue I face with Swift 2.2. After I updated Xcode to Version 7.3, a warning appears with the UIButton code I normally use:
If I ignore the warning and continue to build the code, the UIButton still works perfectly. By clicking the warning triangle, the warning description says that Use of string literal for Objective-C selectors is deprecated; use '#selector' instead.
Select theFix-it Replaceoption.
Then the warning is disappeared as below: button.addTarget(self, action: #selector(ViewController.buttonPressed), forControlEvents: UIControlEvents.TouchUpInside)
Update April 27, 2016: Step 3 - ViewController.swift is modified with Xcode 7.3 (Swift 2.2). This post shows how to display the user email and profile picture with Google Sign-In for iOS. Procedure 1. Create a basic sign-in button with instructions in this tutorial:
May 27, 2016 - Update Step 4 for CocoaPods 1.0. This tutorial explains how to create a Google Sign-In button without storyboard using Google Sign-In for iOS. The code below was developed in Swift 2 with Xcode 7.2.1. More information: Google Sign-In iOS SDK Release Notes Procedure 1. Install CocoaPods. (More information about CocoaPods is written at the bottom of this post.) Type this command in the terminal: sudo gem install cocoapods 2. Create an Xcode project and close it. 3. Go to the project directory in the terminal and type: pod init 4. In the Podfile just created, edit it as below:
(You may open the Podfile with this command: open -a Xcode Podfile) Update May 27, 2016:
The above code may not work with the new CocoaPods 1.0. If you see error like this:
The dependency `GoogleMaps` is not used in any concrete target.
Try modify yourPodfileas below:
target "Project_name" do
5. Run the terminal and type the command below in the project directory:
pod install You may see something like this in the terminal:
5. Open the projectName.xcworkspace file just automatically created. (Don't open the original .xcodeproj file)
You may see the project navigator like this with a new Pods folder:
6. We are going to download a configuration file. Just follow the instructions in the Google Sign-In for iOS page. Click the GET A CONFIGURATION FILE Button.
Enter the App name and iOS Bundle ID. Click CONTINUE TO Choose and configure services.
Click ENABLE GOOGLE SIGN-IN.
Click CONTINUE TO Generate configuration files.
Download the GoogleService-Info.plist file and drag it to the Xcode project.
The above code is derived from Google's ViewController.swift example. Various Sign-In Button Sizes (See GIDSignInButton Class): GIDSignInButtonStyle.Standard => 230x48 GIDSignInButtonStyle.Wide => 312x48 GIDSignInButtonStyle.IconOnly => 48x48 11. If you build the code now, you'll see this error:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Try to disable the bitcode: Targets -> Build Settings -> Build Options -> Enable Bitcode (Search: bitcode) -> No
12. Build and run the code. It should work.
Press the Sign in button.
Enter the ID (Gmail address) and password.
The username is displayed.
============= Additional Information Some CocoaPods commands for reference: 1. Check the CocoaPods version installed: pod --version 2. Check if CocoaPods framework of a project is outdated: Go to the directory including the Podfile. Type:
Thepod outdatedcommand also checks if new CocoaPods version is available. 3. Update CocoaPods using the install command: sudo gem install cocoapods 4. Update CocoaPods to a pre-release version: sudo gem install cocoapods --pre 5. Update local repositories: pod update