Skip to content

convert sample to swift 3 #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 12 additions & 100 deletions samples/swift/uidemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,9 @@
isa = PBXNativeTarget;
buildConfigurationList = 8DABC9A21D3D82D600453807 /* Build configuration list for PBXNativeTarget "uidemo" */;
buildPhases = (
757DE2C28DE66EF8748CA3DA /* [CP] Check Pods Manifest.lock */,
8DABC9811D3D82D600453807 /* Sources */,
8DABC9821D3D82D600453807 /* Frameworks */,
8DABC9831D3D82D600453807 /* Resources */,
766A34E36C2BABD9E53324E8 /* [CP] Embed Pods Frameworks */,
6CC65E746C220141C88C7F20 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -179,12 +176,9 @@
isa = PBXNativeTarget;
buildConfigurationList = 8DABC9A51D3D82D600453807 /* Build configuration list for PBXNativeTarget "uidemoTests" */;
buildPhases = (
235E6CAB9EF32464B5D5C387 /* [CP] Check Pods Manifest.lock */,
8DABC9951D3D82D600453807 /* Sources */,
8DABC9961D3D82D600453807 /* Frameworks */,
8DABC9971D3D82D600453807 /* Resources */,
C6C5C6CC234D3892828C1C9D /* [CP] Embed Pods Frameworks */,
25A95440B19AD17F8CF61ED7 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -203,14 +197,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = morganchen;
TargetAttributes = {
8DABC9841D3D82D600453807 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
};
8DABC9981D3D82D600453807 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
TestTargetID = 8DABC9841D3D82D600453807;
};
};
Expand Down Expand Up @@ -255,99 +251,6 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
235E6CAB9EF32464B5D5C387 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
25A95440B19AD17F8CF61ED7 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-uidemoTests/Pods-uidemoTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
6CC65E746C220141C88C7F20 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-uidemo/Pods-uidemo-resources.sh\"\n";
showEnvVarsInLog = 0;
};
757DE2C28DE66EF8748CA3DA /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
766A34E36C2BABD9E53324E8 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-uidemo/Pods-uidemo-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
C6C5C6CC234D3892828C1C9D /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-uidemoTests/Pods-uidemoTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
8DABC9811D3D82D600453807 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -418,8 +321,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -465,8 +370,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -485,6 +392,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -502,6 +410,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -516,6 +425,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.google.firebase.firebaseui.uidemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -527,6 +437,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.firebase.uidemoTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/uidemo.app/uidemo";
};
name = Debug;
Expand All @@ -539,6 +450,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.firebase.uidemoTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/uidemo.app/uidemo";
};
name = Release;
Expand Down
8 changes: 4 additions & 4 deletions samples/swift/uidemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Successfully running this sample requires an app in Firebase and an
// accompanying valid GoogleService-Info.plist file.
FIRApp.configure()
Fabric.with([Twitter.self])
return true
}

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String?
if FIRAuthUI.defaultAuthUI()?.handleOpenURL(url, sourceApplication: sourceApplication) ?? false {
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String?
if FIRAuthUI.default()?.handleOpen(url, sourceApplication: sourceApplication) ?? false {
return true
}
// other URL handling goes here.
Expand Down
26 changes: 13 additions & 13 deletions samples/swift/uidemo/Samples/Auth/FIRAuthViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import FirebaseGoogleAuthUI
import FirebaseFacebookAuthUI
import FirebaseTwitterAuthUI

let kFirebaseTermsOfService = NSURL(string: "https://firebase.google.com/terms/")!
let kFirebaseTermsOfService = URL(string: "https://firebase.google.com/terms/")!

/// A view controller displaying a basic sign-in flow using FIRAuthUI.
class FIRAuthViewController: UITableViewController {
Expand All @@ -30,10 +30,10 @@ class FIRAuthViewController: UITableViewController {
// info, see the Auth README at ../../FirebaseAuthUI/README.md
// and https://firebase.google.com/docs/auth/

private var authStateDidChangeHandle: FIRAuthStateDidChangeListenerHandle?
fileprivate var authStateDidChangeHandle: FIRAuthStateDidChangeListenerHandle?

private(set) var auth: FIRAuth? = FIRAuth.auth()
private(set) var authUI: FIRAuthUI? = FIRAuthUI.defaultAuthUI()
fileprivate(set) var auth: FIRAuth? = FIRAuth.auth()
fileprivate(set) var authUI: FIRAuthUI? = FIRAuthUI.default()

@IBOutlet weak var cellSignedIn: UITableViewCell!
@IBOutlet weak var cellName: UITableViewCell!
Expand All @@ -45,7 +45,7 @@ class FIRAuthViewController: UITableViewController {
@IBOutlet weak var btnAuthorization: UIBarButtonItem!


override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

self.tableView.rowHeight = UITableViewAutomaticDimension;
Expand All @@ -60,24 +60,24 @@ class FIRAuthViewController: UITableViewController {
]
self.authUI?.providers = providers

self.authUI?.TOSURL = kFirebaseTermsOfService
self.authUI?.tosurl = kFirebaseTermsOfService

self.authStateDidChangeHandle =
self.auth?.addAuthStateDidChangeListener(self.updateUI(auth:user:))
self.auth?.addStateDidChangeListener(self.updateUI(auth:user:))
}

override func viewWillDisappear(animated: Bool) {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if let handle = self.authStateDidChangeHandle {
self.auth?.removeAuthStateDidChangeListener(handle)
self.auth?.removeStateDidChangeListener(handle)
}
}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}

@IBAction func onAuthorize(sender: AnyObject) {
@IBAction func onAuthorize(_ sender: AnyObject) {
if (self.auth?.currentUser) != nil {
do {
try self.auth?.signOut()
Expand All @@ -94,12 +94,12 @@ class FIRAuthViewController: UITableViewController {

} else {
let controller = self.authUI!.authViewController()
self.presentViewController(controller, animated: true, completion: nil)
self.present(controller, animated: true, completion: nil)
}
}

// Boilerplate
func updateUI(auth auth: FIRAuth, user: FIRUser?) {
func updateUI(auth: FIRAuth, user: FIRUser?) {
if let user = self.auth?.currentUser {
self.cellSignedIn.textLabel?.text = "Signed in"
self.cellName.textLabel?.text = user.displayName ?? "(null)"
Expand Down
30 changes: 15 additions & 15 deletions samples/swift/uidemo/Samples/Chat/FIRChatCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import Firebase

/// Displays an individual chat message inside of a FIRChatViewController.
class FIRChatCollectionViewCell: UICollectionViewCell {
@IBOutlet private(set) var textLabel: UILabel! {
@IBOutlet fileprivate(set) var textLabel: UILabel! {
didSet {
textLabel.font = FIRChatCollectionViewCell.messageFont
}
}

static func boundingRectForText(text: String, maxWidth: CGFloat) -> CGRect {
static func boundingRectForText(_ text: String, maxWidth: CGFloat) -> CGRect {
let attributes = [NSFontAttributeName: FIRChatCollectionViewCell.messageFont]
let rect = text.boundingRectWithSize(CGSize(width: maxWidth, height: CGFloat.max),
options: [.UsesLineFragmentOrigin],
let rect = text.boundingRect(with: CGSize(width: maxWidth, height: CGFloat.greatestFiniteMagnitude),
options: [.usesLineFragmentOrigin],
attributes: attributes,
context: nil)
return rect
Expand All @@ -42,22 +42,22 @@ class FIRChatCollectionViewCell: UICollectionViewCell {
}

/// These constraints are used to left- and right-align chat bubbles.
@IBOutlet private(set) var leadingConstraint: NSLayoutConstraint!
@IBOutlet private(set) var trailingConstraint: NSLayoutConstraint!
@IBOutlet fileprivate(set) var leadingConstraint: NSLayoutConstraint!
@IBOutlet fileprivate(set) var trailingConstraint: NSLayoutConstraint!

/// The font used to display chat messages.
/// This is the source of truth for the message font,
/// overriding whatever is set in interface builder.
static var messageFont: UIFont {
return UIFont.systemFontOfSize(UIFont.systemFontSize())
return UIFont.systemFont(ofSize: UIFont.systemFontSize)
}

/// Colors for messages (text and background) sent from the client.
/// White text on a blue background, similar to the Messages app.
static var selfColors: (background: UIColor, text: UIColor) {
return (
background: UIColor(red: 21 / 255, green: 60 / 255, blue: 235 / 255, alpha: 1),
text: UIColor.whiteColor()
text: UIColor.white
)
}

Expand All @@ -66,34 +66,34 @@ class FIRChatCollectionViewCell: UICollectionViewCell {
static var othersColors: (background: UIColor, text: UIColor) {
return (
background: UIColor(red: 230 / 255, green: 230 / 255, blue: 230 / 255, alpha: 1),
text: UIColor.blackColor()
text: UIColor.black
)
}

/// Sets the cell's contents and lays out the cell according
/// to the contents set.
func populateCellWithChat(chat: Chat, user: FIRUser?, maxWidth: CGFloat) {
func populateCellWithChat(_ chat: Chat, user: FIRUser?, maxWidth: CGFloat) {
self.textLabel.text = chat.text

let leftRightPadding: CGFloat = 24
let rect = FIRChatCollectionViewCell.boundingRectForText(self.textLabel.text!,
maxWidth: maxWidth)

let constant = max(maxWidth - rect.size.width - leftRightPadding, CGFloat.min)
let constant = max(maxWidth - rect.size.width - leftRightPadding, CGFloat.leastNormalMagnitude)
if chat.uid == user?.uid ?? "" {
let colors = FIRChatCollectionViewCell.selfColors
self.containerView.backgroundColor = colors.background
self.textLabel.textColor = colors.text
self.trailingConstraint.active = false
self.trailingConstraint.isActive = false
self.leadingConstraint.constant = constant
self.leadingConstraint.active = true
self.leadingConstraint.isActive = true
} else {
let colors = FIRChatCollectionViewCell.othersColors
self.containerView.backgroundColor = colors.background
self.textLabel.textColor = colors.text
self.leadingConstraint.active = false
self.leadingConstraint.isActive = false
self.trailingConstraint.constant = constant
self.trailingConstraint.active = true
self.trailingConstraint.isActive = true
}
}
}
Loading