Code Monkey home page Code Monkey logo

swift-githubreposearch-lab's Introduction

Github Repo Search - Swift (DEPRECATED)

Demo

This is roughly what your app should look like after you've completed the tasks described in these instructions:

<iframe width="560" height="315" src="https://www.youtube.com/embed/08vCCBNpQi0?rel=0&modestbranding=1" frameborder="0" allowfullscreen></iframe>

GitHub Search Demo

Goal

The goal is to search for repositories on Github and display the results in your tableview. The user will tap a UIBarButtonItem such as Search to display a UIAlertController containing a UITextField prompting the user to enter a query. The controller should include two UIAlertActions - one to initiate the search and one to cancel (i.e. dismiss the UIAlertController). After the search is complete, the alert controller should be dismissed and the tableview should be reloaded with the search results. Use Alamofire instead of NSURLSession to make your network calls.

API Calls With Alamofire and SwiftyJSON

1. Declare a variable to hold a URL string connecting us to Github (use appropriate path and access token)
let githubURL = [NSString stringWithFormat:<githubURL>];
2. Use appropriate HTTP verb method in your request
//GET data
Alamofire.request(.GET, url).responseJSON { (response) in
   //you can create a JSON object by using its initializer: JSON(data: response.data)
   //response.result will give you a success enum that you can work with (will either be .Success or .Failure)
}
// GET data with parameters

let params = [name : keyword]

Alamofire.request(.GET, url, parameters: params, encoding: .URL, headers: nil).validate().responseJSON { (response) 
	//pass data back here
}
// PUT data
Alamofire.request(.PUT, url).responseJSON { (response) in
   //you can create a JSON object by using its initializer: JSON(data: response.data)
   //response.result will give you a success enum that you can work with (will either be .Success or .Failure)
}
// DELETE data
Alamofire.request(.DELETE, url).responseJSON { (response) in
   //you can create a JSON object by using its initializer: JSON(data: response.data)
   //response.result will give you a success enum that you can work with (will either be .Success or .Failure)
}

Instructions

  1. Bring over your code from the github-repo-starring lab.

  2. Write a method in GithubAPIClient that searches for repos from the text provided in the alert controller (which you will create). Take a look at the repo search documentation and implement the appropriate method to do a search for repositories.

  3. Add a UIBarButtonItem (with to your TableViewController in Storyboard. When a user taps the button, it should display a UIAlertController that prompts the user to enter a search query. Add a UIAlertAction to initiate the search. This is my favorite resource on UIAlertController.

  4. Re-implement the getRepositories and star/unstar methods using Alamofire instead of NSURLSession. If you didn't complete the Github Repo Starring lab, reference those instructions implementing the methods using Alamofire.

Hint: The JSON object that you serialize in your API Client contains more JSON objects. In you data store, if you iterate through the JSON object that you receive back from the API client, you will be able to access those sub-objects. Assuming that the sub-objects are named json, each sub-object contains an index (which can be accessed by json.0) and the actual value (which can be accessed by json.1 - in the case of this lab, json.1 will give you a dictionary).

When you have the dictionary that you need, you can access the values in those dictionaries like this: dictionary["full_name"].string (substituting the correct value type for string`.

swift-githubreposearch-lab's People

Contributors

ianrahman avatar susanlovaglio avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.