Giter Site home page Giter Site logo

ac3.2-violations's Introduction

AC3.2-Violations

,---.  ,---.-./`)    ,-----.     .---.       ____  ,---------..-./`)    ,-----.   ,---.   .--.  .-'''-.  
|   /  |   \ .-.') .'  .-,  '.   | ,_|     .'  __ `\          \ .-.') .'  .-,  '. |    \  |  | / _     \ 
|  |   |  ./ `-' \/ ,-.|  \ _ \,-./  )    /   '  \  `--.  ,---/ `-' \/ ,-.|  \ _ \|  ,  \ |  |(`' )/`--' 
|  | _ |  | `-'`";  \  '_ /  | \  '_ '`)  |___|  /  |  |   \   `-'`";  \  '_ /  | |  |\_ \|  (_ o _).    
|  _( )_  | .---.|  _`,/ \ _/  |> (_)  )     _.-`   |  :_ _:   .---.|  _`,/ \ _/  |  _( )_\  |(_,_). '.  
\ (_ o._) / |   |: (  '\_/ \   (  .  .-'  .'   _    |  (_I_)   |   |: (  '\_/ \   | (_ o _)  .---.  \  : 
 \ (_,_) /  |   | \ `"/  \  ) / `-'`-'|___|  _( )_  | (_(=)_)  |   | \ `"/  \  ) /|  (_,_)\  \    `-'  | 
  \     /   |   |  '. \_/``".'   |        \ (_ o _) /  (_I_)   |   |  '. \_/``".' |  |    |  |\       /  
   `---`    '---'    '-----'     `--------`'.(_,_).'   '---'   '---'    '-----'   '--'    '--' `-...-'   
                                                                                                         
                                                                                                                 

Objectives

  • To reinforce Table Views by exercising
    • The three key data source delegate methods
    • Storyboard segues
    • Passing data to a view controller in prepare(for:)

Assignment

Let's look at some gut-churning data about restaurants in our neighborhood!

Steps

  1. NEW STEP! Let's get rid of those unsightly .DS_Store files, why don't we? Run the following two commands in Terminal from ANY directory. The reason the directory doesn't matter is because we're configuring git globally. That tilde is a shortcut to your home directory and so that's why you can be in any directory when you type this.

    git config --global core.excludesfile ~/.gitignore
    echo .DS_Store >> ~/.gitignore
    
  2. Fork this repo.

  3. Go to your own fork. To verify this, check that your github username is in the URL and C4Q's isn't. Note Safari doesn't reveal the full URL until you click on it. (For this and other reasons I use Chrome).

  4. Clone your own fork of the repo. This is done by clicking the green Clone or download button, copying the URL, going to your project directory and typing:

    git clone <url_you_just_copied>
    
  5. Work on your project.

  6. When done, commit and push to your repo.

Instructions

This time, after you clone the project and open it you should have practically nothing. This is just the output of the Single View application wizard. The only difference between this this project and the Game of Thrones project is the data file. That file is included: violations.json.

As part of the process of using the GoT project as a model you'll want to do the following:

  1. Make a custom class file to hold your violation data. You'll probably want to name the class Violations and name the file accordingly. Refer to GOTEpisode.swift for ideas. You can treat all fields as String.

  2. Read the data in from the JSON file included in the project. This step is not the focus of the exercise so just set it up and don't think about it yet.

    Add this method to your UITableViewController subclass:

    func loadData() {
        guard let path = Bundle.main.path(forResource: "violations", ofType: "json"),
            let jsonData = try? Data(contentsOf: URL(fileURLWithPath: path), options:  NSData.ReadingOptions.mappedIfSafe),
            let violationsJSON = try? JSONSerialization.jsonObject(with: jsonData as Data, options: .allowFragments) as? NSArray else {
                return
        }
    
        if let violations = violationsJSON as? [[String:Any]] {
            for violationDict in violations {
                if let ep = Violation(withDict: violationDict) {
                    self.episodes.append(ep)
                }
            }
        }
    }
  3. Repeat the act of not repeating step 1.

  4. Be creative. Read the JSON file and decide which fields you want to go where, in the table cell and the detail.

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.