cs193p – Smashtag Update Swift 1.2

Please note, this blog entry is from a previous course. You might want to check out the current one.

To run the Smashtag code with Swift 1.2. are quite extensive:

  • countElements() is now called count()
  • as needs to be replaced with as!
  • reduce() requires the combine parameter named explicitly
  • same with custom methods, its now quite strict …
  • let is now more restrictive, some parameters have to be changed to var (it might be I went a little bit over board here)
  • NSString is no String any more and needs to be cast explicitly
  • if a parameter is set within a closure of the init method, set a default value outside

The updated code is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #4 Assignment #4 Extra Task #6

Please note, this blog entry is from a previous course. You might want to check out the current one.

Add some UI which displays a new view controller showing a UICollectionView of the first image (or all the images if you want) in all the Tweets that match the search. When a user clicks on an image in this UICollectionView, segue to showing them the Tweet.


Let’s start with the storyboard:

  • Add a collection view controller.
  • Add a segue from the tweet table view controller to the new controller (note: from the controller itself not from one of its elements or table cells) and name the segue.
  • Add a button to the right side of the navigation bar and link it to the unwind method from extra task #3
  • Add a reuse identifier for the collection view cell.
  • Add an image view to the cell (including autolayout constraints).
  • Add an activity indicator on top (including constraints)
  • Finally add a segue from the cell back to the tweets table view controller and name it.

Continue reading “cs193p – Project #4 Assignment #4 Extra Task #6”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #4 Assignment #4 Extra Task #5

Please note, this blog entry is from a previous course. You might want to check out the current one.

Make the “most recent searches” table be editable (i.e. let the user swipe left to delete the ones they don’t like).

We need a new method for our model/data source to be able to delete an entry from the user defaults:

    func removeAtIndex(index: Int) {
        var currentSearches = values
        currentSearches.removeAtIndex(index)
        values = currentSearches
    }

… and use it before removing the line from the table:

    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            RecentSearches().removeAtIndex(indexPath.row)
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        }
    }

The complete code for extra task #5 is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #4 Assignment #4 Extra Task #4

Please note, this blog entry is from a previous course. You might want to check out the current one.

Instead of opening urls in Safari, display them in your application by segueing to a controller with a UIWebView. You’ll have to provide at least a little bit of “browser control” UI to go along with it (e.g. a “back button”).

Add a new view controller to the storyboard. Add a egue from the mentions table view controller to the new controller (be careful, not from a cell, but from the controller itself!). Add a web view, an activity indicator and a back button (don’t forget constraints for autolayout):

cs193p - Project #4 Assignment #4 Extra Task #4 - web view controller
cs193p – Project #4 Assignment #4 Extra Task #4 – web view controller

Continue reading “cs193p – Project #4 Assignment #4 Extra Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #4 Assignment #4 Extra Task #3

Please note, this blog entry is from a previous course. You might want to check out the current one.

If you segue using Show (rather than Unwind), add some UI which will Unwind all the way back to the rootViewController of the UINavigationController. Even if you use Unwind (rather than Show), then if do the Collection View extra credit below using a Show segue, you might want the “unwind to root” behavior in scenes you segue to via the Collection View.

In both “root” view controllers (the tweet table view controller and the recent-searches table view controller) of the tab view controller add an unwind function as destination for the unwinding:

    @IBAction func unwindToRoot(sender: UIStoryboardSegue) { }

Continue reading “cs193p – Project #4 Assignment #4 Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #4 Assignment #4 Extra Task #2

Please note, this blog entry is from a previous course. You might want to check out the current one.

When you click on a user in the Users section, search not only for Tweets that mention that user, but also for Tweets which were posted by that user.

If the query is a user name (starts with an @ sign) change the search query to look also for the poster:

    var nextRequestToAttempt: TwitterRequest? {
        ...
            if searchText != nil {
                var query = searchText!
                if query.hasPrefix("@") {
                    query = "\(query) OR from:\(query)"
                }
                return TwitterRequest(search: query, count: 100)
            } ...
    }

The complete code for extra task #2 is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #4 Assignment #4 Extra Task #1

Please note, this blog entry is from a previous course. You might want to check out the current one.

In the Users section of your new UITableViewController, list not only users mentioned in the Tweet, but also the user who posted the Tweet in the first place.

Add the users screen name including a leading @ sign:

    var tweet: Tweet? {
        didSet {
            ...
            if let users = tweet?.userMentions {
                var userItems = [MentionItem.Keyword("@" + tweet!.user.screenName)]
                if users.count > 0 {
                    userItems += users.map { MentionItem.Keyword($0.keyword) }
                }
                mentions.append(Mentions(title: "Users", data: userItems))
            }
        }
    }

The complete code for extra task #1 is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail