Git Product home page Git Product logo

swift-github-repo-search-lab-g-416's Introduction

Swift Github Repo Search

Demo

<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 URLSession to make your network calls.

API Calls

It will be useful to read the usage instructions of Alamofire before proceeding, but below are some high-level guidelines.

0. Bring Alamofire into your API Client
import Alamofire
1. Declare a property to hold a URL string connecting us to GitHub (use appropriate path and access token, which should be in Secrets.swift)
let githubURL: String = "https://api.github.com"
2. Pass your URL into an Alamofire request and handle the response within the response handler
//GET data
Alamofire.request(githubURL).responseJSON { response in
    print(response.request)  // original URL request
    print(response.response) // HTTP URL response
    print(response.error)    // any error, if one exists
    print(response.data)     // server data
    print(response.result)   // result of response serialization

    if let JSON = response.result.value {
        print("JSON: \(JSON)")
    }
}
3. Use the appropriate HTTP Method verb in your request
// GET data with parameters
let params = [name : keyword] // Parameters are optional

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

Apple's thoughts and feelings on JSON with Swift

  1. Bring over your code from the GitHub Repo Starring lab. After dragging over your files, make sure you reestablish any connections needed in your project file. You will need:
  • Secrets.swift

  • GithubAPIClient.swift

  • DataStore.swift

  • TableViewController.swift

  • Main.storyboard (you may need to recreate your storyboard instead of dragging it over)

  1. 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.

  2. Add a UIBarButtonItem such as Search 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 a good resource on UIAlertController.

  3. Re-implement the star/unstar methods using Alamofire instead of URLSession. If you didn't complete the Github-Starring lab, reference those instructions implementing the methods using Alamofire.

View swift-github-repo-search-lab on Learn.co and start learning to code for free.

swift-github-repo-search-lab-g-416's People

Contributors

ianrahman avatar susanlovaglio avatar

Watchers

 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.