-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract twitter delegate into a separate file since this is a shared …
…functionality now
- Loading branch information
Showing
4 changed files
with
47 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// TwitterFollowDelegate.swift | ||
// trySwift | ||
// | ||
// Created by Sash Zats on 3/2/18. | ||
// Copyright © 2018 NatashaTheRobot. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
protocol TwitterFollowDelegate: class { | ||
func followUser(_ username: String) | ||
} | ||
|
||
extension UIViewController: TwitterFollowDelegate { | ||
|
||
func followUser(_ username: String) { | ||
var applicationOpened = false | ||
let application = UIApplication.shared | ||
for twitterURL in Twitter.urls(forUsername: username) { | ||
if let url = URL(string: twitterURL) , application.canOpenURL(url) && !applicationOpened { | ||
application.open(url, options: [String:Any](), completionHandler: nil) | ||
applicationOpened = true | ||
break | ||
} | ||
} | ||
|
||
if !applicationOpened { | ||
if let twitterURL = URL(string: "https://twitter.com/\(username)") { | ||
openSafariViewController(withURL: twitterURL) | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters