Skip to content

Commit b4b9ae2

Browse files
committed
convert sample to swift 3
1 parent 54d929f commit b4b9ae2

10 files changed

+138
-226
lines changed

samples/swift/uidemo.xcodeproj/project.pbxproj

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,9 @@
159159
isa = PBXNativeTarget;
160160
buildConfigurationList = 8DABC9A21D3D82D600453807 /* Build configuration list for PBXNativeTarget "uidemo" */;
161161
buildPhases = (
162-
757DE2C28DE66EF8748CA3DA /* [CP] Check Pods Manifest.lock */,
163162
8DABC9811D3D82D600453807 /* Sources */,
164163
8DABC9821D3D82D600453807 /* Frameworks */,
165164
8DABC9831D3D82D600453807 /* Resources */,
166-
766A34E36C2BABD9E53324E8 /* [CP] Embed Pods Frameworks */,
167-
6CC65E746C220141C88C7F20 /* [CP] Copy Pods Resources */,
168165
);
169166
buildRules = (
170167
);
@@ -179,12 +176,9 @@
179176
isa = PBXNativeTarget;
180177
buildConfigurationList = 8DABC9A51D3D82D600453807 /* Build configuration list for PBXNativeTarget "uidemoTests" */;
181178
buildPhases = (
182-
235E6CAB9EF32464B5D5C387 /* [CP] Check Pods Manifest.lock */,
183179
8DABC9951D3D82D600453807 /* Sources */,
184180
8DABC9961D3D82D600453807 /* Frameworks */,
185181
8DABC9971D3D82D600453807 /* Resources */,
186-
C6C5C6CC234D3892828C1C9D /* [CP] Embed Pods Frameworks */,
187-
25A95440B19AD17F8CF61ED7 /* [CP] Copy Pods Resources */,
188182
);
189183
buildRules = (
190184
);
@@ -203,14 +197,16 @@
203197
isa = PBXProject;
204198
attributes = {
205199
LastSwiftUpdateCheck = 0730;
206-
LastUpgradeCheck = 0730;
200+
LastUpgradeCheck = 0800;
207201
ORGANIZATIONNAME = morganchen;
208202
TargetAttributes = {
209203
8DABC9841D3D82D600453807 = {
210204
CreatedOnToolsVersion = 7.3.1;
205+
LastSwiftMigration = 0800;
211206
};
212207
8DABC9981D3D82D600453807 = {
213208
CreatedOnToolsVersion = 7.3.1;
209+
LastSwiftMigration = 0800;
214210
TestTargetID = 8DABC9841D3D82D600453807;
215211
};
216212
};
@@ -255,99 +251,6 @@
255251
};
256252
/* End PBXResourcesBuildPhase section */
257253

258-
/* Begin PBXShellScriptBuildPhase section */
259-
235E6CAB9EF32464B5D5C387 /* [CP] Check Pods Manifest.lock */ = {
260-
isa = PBXShellScriptBuildPhase;
261-
buildActionMask = 2147483647;
262-
files = (
263-
);
264-
inputPaths = (
265-
);
266-
name = "[CP] Check Pods Manifest.lock";
267-
outputPaths = (
268-
);
269-
runOnlyForDeploymentPostprocessing = 0;
270-
shellPath = /bin/sh;
271-
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";
272-
showEnvVarsInLog = 0;
273-
};
274-
25A95440B19AD17F8CF61ED7 /* [CP] Copy Pods Resources */ = {
275-
isa = PBXShellScriptBuildPhase;
276-
buildActionMask = 2147483647;
277-
files = (
278-
);
279-
inputPaths = (
280-
);
281-
name = "[CP] Copy Pods Resources";
282-
outputPaths = (
283-
);
284-
runOnlyForDeploymentPostprocessing = 0;
285-
shellPath = /bin/sh;
286-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-uidemoTests/Pods-uidemoTests-resources.sh\"\n";
287-
showEnvVarsInLog = 0;
288-
};
289-
6CC65E746C220141C88C7F20 /* [CP] Copy Pods Resources */ = {
290-
isa = PBXShellScriptBuildPhase;
291-
buildActionMask = 2147483647;
292-
files = (
293-
);
294-
inputPaths = (
295-
);
296-
name = "[CP] Copy Pods Resources";
297-
outputPaths = (
298-
);
299-
runOnlyForDeploymentPostprocessing = 0;
300-
shellPath = /bin/sh;
301-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-uidemo/Pods-uidemo-resources.sh\"\n";
302-
showEnvVarsInLog = 0;
303-
};
304-
757DE2C28DE66EF8748CA3DA /* [CP] Check Pods Manifest.lock */ = {
305-
isa = PBXShellScriptBuildPhase;
306-
buildActionMask = 2147483647;
307-
files = (
308-
);
309-
inputPaths = (
310-
);
311-
name = "[CP] Check Pods Manifest.lock";
312-
outputPaths = (
313-
);
314-
runOnlyForDeploymentPostprocessing = 0;
315-
shellPath = /bin/sh;
316-
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";
317-
showEnvVarsInLog = 0;
318-
};
319-
766A34E36C2BABD9E53324E8 /* [CP] Embed Pods Frameworks */ = {
320-
isa = PBXShellScriptBuildPhase;
321-
buildActionMask = 2147483647;
322-
files = (
323-
);
324-
inputPaths = (
325-
);
326-
name = "[CP] Embed Pods Frameworks";
327-
outputPaths = (
328-
);
329-
runOnlyForDeploymentPostprocessing = 0;
330-
shellPath = /bin/sh;
331-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-uidemo/Pods-uidemo-frameworks.sh\"\n";
332-
showEnvVarsInLog = 0;
333-
};
334-
C6C5C6CC234D3892828C1C9D /* [CP] Embed Pods Frameworks */ = {
335-
isa = PBXShellScriptBuildPhase;
336-
buildActionMask = 2147483647;
337-
files = (
338-
);
339-
inputPaths = (
340-
);
341-
name = "[CP] Embed Pods Frameworks";
342-
outputPaths = (
343-
);
344-
runOnlyForDeploymentPostprocessing = 0;
345-
shellPath = /bin/sh;
346-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-uidemoTests/Pods-uidemoTests-frameworks.sh\"\n";
347-
showEnvVarsInLog = 0;
348-
};
349-
/* End PBXShellScriptBuildPhase section */
350-
351254
/* Begin PBXSourcesBuildPhase section */
352255
8DABC9811D3D82D600453807 /* Sources */ = {
353256
isa = PBXSourcesBuildPhase;
@@ -418,8 +321,10 @@
418321
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
419322
CLANG_WARN_EMPTY_BODY = YES;
420323
CLANG_WARN_ENUM_CONVERSION = YES;
324+
CLANG_WARN_INFINITE_RECURSION = YES;
421325
CLANG_WARN_INT_CONVERSION = YES;
422326
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
327+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
423328
CLANG_WARN_UNREACHABLE_CODE = YES;
424329
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
425330
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -465,8 +370,10 @@
465370
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
466371
CLANG_WARN_EMPTY_BODY = YES;
467372
CLANG_WARN_ENUM_CONVERSION = YES;
373+
CLANG_WARN_INFINITE_RECURSION = YES;
468374
CLANG_WARN_INT_CONVERSION = YES;
469375
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
376+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
470377
CLANG_WARN_UNREACHABLE_CODE = YES;
471378
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
472379
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -485,6 +392,7 @@
485392
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
486393
MTL_ENABLE_DEBUG_INFO = NO;
487394
SDKROOT = iphoneos;
395+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
488396
TARGETED_DEVICE_FAMILY = "1,2";
489397
VALIDATE_PRODUCT = YES;
490398
};
@@ -502,6 +410,7 @@
502410
PRODUCT_NAME = "$(TARGET_NAME)";
503411
SWIFT_OBJC_BRIDGING_HEADER = "";
504412
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
413+
SWIFT_VERSION = 3.0;
505414
};
506415
name = Debug;
507416
};
@@ -516,6 +425,7 @@
516425
PRODUCT_BUNDLE_IDENTIFIER = com.google.firebase.firebaseui.uidemo;
517426
PRODUCT_NAME = "$(TARGET_NAME)";
518427
SWIFT_OBJC_BRIDGING_HEADER = "";
428+
SWIFT_VERSION = 3.0;
519429
};
520430
name = Release;
521431
};
@@ -527,6 +437,7 @@
527437
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
528438
PRODUCT_BUNDLE_IDENTIFIER = com.firebase.uidemoTests;
529439
PRODUCT_NAME = "$(TARGET_NAME)";
440+
SWIFT_VERSION = 3.0;
530441
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/uidemo.app/uidemo";
531442
};
532443
name = Debug;
@@ -539,6 +450,7 @@
539450
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
540451
PRODUCT_BUNDLE_IDENTIFIER = com.firebase.uidemoTests;
541452
PRODUCT_NAME = "$(TARGET_NAME)";
453+
SWIFT_VERSION = 3.0;
542454
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/uidemo.app/uidemo";
543455
};
544456
name = Release;

samples/swift/uidemo/AppDelegate.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2525

2626
var window: UIWindow?
2727

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

36-
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
37-
let sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String?
38-
if FIRAuthUI.defaultAuthUI()?.handleOpenURL(url, sourceApplication: sourceApplication) ?? false {
36+
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
37+
let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String?
38+
if FIRAuthUI.default()?.handleOpen(url, sourceApplication: sourceApplication) ?? false {
3939
return true
4040
}
4141
// other URL handling goes here.

samples/swift/uidemo/Samples/Auth/FIRAuthViewController.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import FirebaseGoogleAuthUI
2121
import FirebaseFacebookAuthUI
2222
import FirebaseTwitterAuthUI
2323

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

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

33-
private var authStateDidChangeHandle: FIRAuthStateDidChangeListenerHandle?
33+
fileprivate var authStateDidChangeHandle: FIRAuthStateDidChangeListenerHandle?
3434

35-
private(set) var auth: FIRAuth? = FIRAuth.auth()
36-
private(set) var authUI: FIRAuthUI? = FIRAuthUI.defaultAuthUI()
35+
fileprivate(set) var auth: FIRAuth? = FIRAuth.auth()
36+
fileprivate(set) var authUI: FIRAuthUI? = FIRAuthUI.default()
3737

3838
@IBOutlet weak var cellSignedIn: UITableViewCell!
3939
@IBOutlet weak var cellName: UITableViewCell!
@@ -45,7 +45,7 @@ class FIRAuthViewController: UITableViewController {
4545
@IBOutlet weak var btnAuthorization: UIBarButtonItem!
4646

4747

48-
override func viewWillAppear(animated: Bool) {
48+
override func viewWillAppear(_ animated: Bool) {
4949
super.viewWillAppear(animated)
5050

5151
self.tableView.rowHeight = UITableViewAutomaticDimension;
@@ -60,24 +60,24 @@ class FIRAuthViewController: UITableViewController {
6060
]
6161
self.authUI?.providers = providers
6262

63-
self.authUI?.TOSURL = kFirebaseTermsOfService
63+
self.authUI?.tosurl = kFirebaseTermsOfService
6464

6565
self.authStateDidChangeHandle =
66-
self.auth?.addAuthStateDidChangeListener(self.updateUI(auth:user:))
66+
self.auth?.addStateDidChangeListener(self.updateUI(auth:user:))
6767
}
6868

69-
override func viewWillDisappear(animated: Bool) {
69+
override func viewWillDisappear(_ animated: Bool) {
7070
super.viewWillDisappear(animated)
7171
if let handle = self.authStateDidChangeHandle {
72-
self.auth?.removeAuthStateDidChangeListener(handle)
72+
self.auth?.removeStateDidChangeListener(handle)
7373
}
7474
}
7575

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

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

9595
} else {
9696
let controller = self.authUI!.authViewController()
97-
self.presentViewController(controller, animated: true, completion: nil)
97+
self.present(controller, animated: true, completion: nil)
9898
}
9999
}
100100

101101
// Boilerplate
102-
func updateUI(auth auth: FIRAuth, user: FIRUser?) {
102+
func updateUI(auth: FIRAuth, user: FIRUser?) {
103103
if let user = self.auth?.currentUser {
104104
self.cellSignedIn.textLabel?.text = "Signed in"
105105
self.cellName.textLabel?.text = user.displayName ?? "(null)"

samples/swift/uidemo/Samples/Chat/FIRChatCollectionViewCell.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import Firebase
1919

2020
/// Displays an individual chat message inside of a FIRChatViewController.
2121
class FIRChatCollectionViewCell: UICollectionViewCell {
22-
@IBOutlet private(set) var textLabel: UILabel! {
22+
@IBOutlet fileprivate(set) var textLabel: UILabel! {
2323
didSet {
2424
textLabel.font = FIRChatCollectionViewCell.messageFont
2525
}
2626
}
2727

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

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

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

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

@@ -66,34 +66,34 @@ class FIRChatCollectionViewCell: UICollectionViewCell {
6666
static var othersColors: (background: UIColor, text: UIColor) {
6767
return (
6868
background: UIColor(red: 230 / 255, green: 230 / 255, blue: 230 / 255, alpha: 1),
69-
text: UIColor.blackColor()
69+
text: UIColor.black
7070
)
7171
}
7272

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

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

82-
let constant = max(maxWidth - rect.size.width - leftRightPadding, CGFloat.min)
82+
let constant = max(maxWidth - rect.size.width - leftRightPadding, CGFloat.leastNormalMagnitude)
8383
if chat.uid == user?.uid ?? "" {
8484
let colors = FIRChatCollectionViewCell.selfColors
8585
self.containerView.backgroundColor = colors.background
8686
self.textLabel.textColor = colors.text
87-
self.trailingConstraint.active = false
87+
self.trailingConstraint.isActive = false
8888
self.leadingConstraint.constant = constant
89-
self.leadingConstraint.active = true
89+
self.leadingConstraint.isActive = true
9090
} else {
9191
let colors = FIRChatCollectionViewCell.othersColors
9292
self.containerView.backgroundColor = colors.background
9393
self.textLabel.textColor = colors.text
94-
self.leadingConstraint.active = false
94+
self.leadingConstraint.isActive = false
9595
self.trailingConstraint.constant = constant
96-
self.trailingConstraint.active = true
96+
self.trailingConstraint.isActive = true
9797
}
9898
}
9999
}

0 commit comments

Comments
 (0)