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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Guess the number!</title> | |
<style> | |
body { | |
background-color: #0A212A; | |
color: #A3BCC5; |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Guess the number!</title> | |
<style> | |
body { | |
background-color: #0A212A; | |
color: #A3BCC5; |
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
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { | |
if segue.identifier == "singleTweetSegue" { | |
var destination = segue.destinationViewController as SingleTweetViewController | |
var indexPath = tableView.indexPathForSelectedRow() | |
tableView.deselectRowAtIndexPath(indexPath!, animated: true) | |
var tweetToDisplay = self.tweets![indexPath!.row] as Tweet | |
destination.tweetShown = tweetToDisplay | |
} | |
} |
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
func fetchTimeLine (timelineType: String, userScreenname: String?, completionHandler: (errorDescription : String?, tweets : [Tweet]?) -> Void) { | |
let accountStore = ACAccountStore() | |
let accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter) | |
/* The following is asynchronous. | |
We will ask for account access, set up a twitter request, then call the home timeline */ | |
accountStore.requestAccessToAccountsWithType(accountType, options: nil) { (granted: Bool, error: NSError!) -> Void in | |
if granted { | |
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
override func viewWillAppear(animated: Bool) { | |
self.singleTweetUserName.text = self.tweetShown!.profileName | |
self.singleTweetTwitterHandle.text = ("@\(self.tweetShown!.screenName)") | |
self.singleTweetText.text = self.tweetShown!.text | |
self.singleTweetProfileImage.image = self.tweetShown!.profileImage | |
self.singleTweetFavoritesCount.text = String(self.tweetShown!.favoriteCount) | |
self.singleTweetRTsCount.text = String(self.tweetShown!.retweetCount) | |
let press = UITapGestureRecognizer(target: self, action: Selector("segueAction:")) | |
self.singleTweetProfileImage.addGestureRecognizer(press) |
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
/* Takes the URL string and changes it to pull Twitter's bigger profile image. | |
Courtesy of Cameron Klein (github.com/cameronklein) */ | |
let normalRange = smallProfileImageURL.rangeOfString("_normal", options: nil, range: nil, locale: nil) | |
self.profileImageURL = smallProfileImageURL.stringByReplacingCharactersInRange(normalRange!, withString: "_bigger") |
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
/* Taken from stackOverflow http://stackoverflow.com/questions/24475792/how-to-use-pull-to-refresh-in-swift */ | |
self.refreshControl = UIRefreshControl() | |
self.refreshControl?.attributedTitle = NSAttributedString(string: "Pull to refresh") | |
self.refreshControl?.addTarget(self, action: "refreshTweets:", forControlEvents: UIControlEvents.ValueChanged) | |
self.tableView.addSubview(self.refreshControl!) | |
func refreshTweets (sender: AnyObject) { | |
NetworkController.controller.fetchTimeLine(timelineType, isRefresh: true, newestTweet: self.tweets?[0], userScreenname: userTimelineShown) { (errorDescription, tweets) -> Void in | |
if errorDescription != nil { |
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
//MARK: - Social Methods | |
func tweet(message: String?, image: UIImage?, url: NSURL?) { | |
let accountStore = ACAccountStore() | |
let accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter) | |
accountStore.requestAccessToAccountsWithType(accountType, options: nil) { (granted: Bool, error: NSError!) -> Void in | |
if granted { | |
let accounts = accountStore.accountsWithAccountType(accountType) | |
self.twitterAccount = accounts.first as? ACAccount | |
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) { |
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
func search (searchString: String, type: SearchType, completionHandler: (returnedArray: [AnyObject], errorDescription: String?) -> Void) { | |
let searchReposURL = "https://api.github.com/search/repositories?q=" | |
let searchUsersURL = "https://api.github.com/search/users?q=" | |
let cleanedSearch = searchString.stringByReplacingOccurrencesOfString(" ", withString: "+", options: nil, range: nil) | |
var url : NSURL? | |
switch type { | |
case .Repos: | |
url = NSURL(string: (searchReposURL + cleanedSearch))? | |
case .Users: | |
url = NSURL(string: (searchUsersURL + cleanedSearch))? |
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
- (void)postDot: (Dot*)dot completionHandler: (void (^)(NSString *error, bool success))completionHandler { | |
NSString *fullURLString = [NSString stringWithFormat: @"%@dots/", self.url]; | |
NSURL *fullURL = [NSURL URLWithString:fullURLString]; | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fullURL]; | |
request.HTTPMethod = @"POST"; | |
NSData *dotJSONData = [dot parseDotIntoJSON]; | |
NSUInteger length = dotJSONData.length; | |
[request setValue:[NSString stringWithFormat:@"%li", length] forHTTPHeaderField:@"Content-Length"]; | |
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; | |
request.HTTPBody = dotJSONData; |