Skip to content

Commit f3dc804

Browse files
committed
Extract twitter delegate into a separate file since this is a shared functionality now
1 parent cc957c2 commit f3dc804

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

trySwift.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
499CCFF21CC2E0F4007A5BBB /* UIViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */; };
2828
49F7B2811E8475F900F09768 /* SplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F7B2801E8475F900F09768 /* SplitViewController.swift */; };
2929
4D498DB1B98D4B496FDBB7AA /* Pods_try__Extension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD2E9D5733A6E1B6E10AFEEF /* Pods_try__Extension.framework */; };
30+
5CDB20792048952A00C3E0D3 /* TwitterFollowDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */; };
3031
7AD1E19C80B78BB08E3DF079 /* Pods_trySwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 620220ABCCCDF47FDAF48B67 /* Pods_trySwift.framework */; };
3132
EAFE1C26E49EFABF83487BDC /* Pods_try__Today.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24718BF11477753FCD47A7A8 /* Pods_try__Today.framework */; };
3233
FA0E2B4F1E63B90400B40814 /* SessionDetailInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA0E2B4E1E63B90400B40814 /* SessionDetailInterfaceController.swift */; };
@@ -193,6 +194,7 @@
193194
499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtension.swift; sourceTree = "<group>"; };
194195
49F7B2801E8475F900F09768 /* SplitViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = "<group>"; };
195196
58F81AD508535BD405F98215 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
197+
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwitterFollowDelegate.swift; sourceTree = "<group>"; };
196198
5FA07FBC036240AEF8B7C739 /* Pods-trySwift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-trySwift.release.xcconfig"; path = "Pods/Target Support Files/Pods-trySwift/Pods-trySwift.release.xcconfig"; sourceTree = "<group>"; };
197199
620220ABCCCDF47FDAF48B67 /* Pods_trySwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_trySwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
198200
6C1F9C27BCD8099DCA758F7A /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
@@ -381,6 +383,14 @@
381383
name = Frameworks;
382384
sourceTree = "<group>";
383385
};
386+
5CDB20772048951F00C3E0D3 /* Twitter */ = {
387+
isa = PBXGroup;
388+
children = (
389+
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */,
390+
);
391+
path = Twitter;
392+
sourceTree = "<group>";
393+
};
384394
F413680C9BA29129B4319377 /* Pods */ = {
385395
isa = PBXGroup;
386396
children = (
@@ -449,6 +459,7 @@
449459
FA39E8CB1C6AF89D0074B6BE /* Utilities */ = {
450460
isa = PBXGroup;
451461
children = (
462+
5CDB20772048951F00C3E0D3 /* Twitter */,
452463
FA39E8ED1C6C034B0074B6BE /* UIColorExtension.swift */,
453464
499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */,
454465
FA3A1CB51D68E1950042F8DD /* WatchSessionManager.swift */,
@@ -1123,6 +1134,7 @@
11231134
isa = PBXSourcesBuildPhase;
11241135
buildActionMask = 2147483647;
11251136
files = (
1137+
5CDB20792048952A00C3E0D3 /* TwitterFollowDelegate.swift in Sources */,
11261138
499BD62A1D05910200E74061 /* Twitter.swift in Sources */,
11271139
FA39E90F1C6C81870074B6BE /* SponsorsViewController.swift in Sources */,
11281140
FA36B7071E5DA3970022E6A9 /* DateFormatterExtension.swift in Sources */,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// TwitterFollowDelegate.swift
3+
// trySwift
4+
//
5+
// Created by Sash Zats on 3/2/18.
6+
// Copyright © 2018 NatashaTheRobot. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
protocol TwitterFollowDelegate: class {
12+
func followUser(_ username: String)
13+
}
14+
15+
extension UIViewController: TwitterFollowDelegate {
16+
17+
func followUser(_ username: String) {
18+
var applicationOpened = false
19+
let application = UIApplication.shared
20+
for twitterURL in Twitter.urls(forUsername: username) {
21+
if let url = URL(string: twitterURL) , application.canOpenURL(url) && !applicationOpened {
22+
application.open(url, options: [String:Any](), completionHandler: nil)
23+
applicationOpened = true
24+
break
25+
}
26+
}
27+
28+
if !applicationOpened {
29+
if let twitterURL = URL(string: "https://twitter.com/\(username)") {
30+
openSafariViewController(withURL: twitterURL)
31+
}
32+
}
33+
}
34+
}
35+

trySwift/TwitterFollowTableViewCell.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
import UIKit
1010

11-
protocol TwitterFollowDelegate: class {
12-
func followUser(_ username: String)
13-
}
14-
1511
class TwitterFollowTableViewCell: UITableViewCell {
1612

1713
@IBOutlet weak var followButton: UIButton!

trySwift/UIViewControllerExtension.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,6 @@ extension UIViewController: SFSafariViewControllerDelegate {
2323
}
2424
}
2525

26-
extension UIViewController: TwitterFollowDelegate {
27-
28-
func followUser(_ username: String) {
29-
var applicationOpened = false
30-
let application = UIApplication.shared
31-
for twitterURL in Twitter.urls(forUsername: username) {
32-
if let url = URL(string: twitterURL) , application.canOpenURL(url) && !applicationOpened {
33-
application.open(url, options: [String:Any](), completionHandler: nil)
34-
applicationOpened = true
35-
break
36-
}
37-
}
38-
39-
if !applicationOpened {
40-
if let twitterURL = URL(string: "https://twitter.com/\(username)") {
41-
openSafariViewController(withURL: twitterURL)
42-
}
43-
}
44-
}
45-
}
46-
4726
extension UIViewController: MFMailComposeViewControllerDelegate {
4827

4928
func sendMail(withConfiguration configuration: MailConfiguration) {

0 commit comments

Comments
 (0)