Coder Social home page Coder Social logo

cmoulton / grokswiftrest_v1.2 Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 4.0 70 KB

Demo code for iOS Apps with REST APIs book v1.2 - For Swift 3 version go to https://github.com/cmoulton/grokSwiftREST_v1.3

Home Page: https://leanpub.com/iosappswithrest

License: MIT License

Ruby 0.54% Swift 99.46%

grokswiftrest_v1.2's People

Contributors

cmoulton avatar sebastianbachmann avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

grokswiftrest_v1.2's Issues

Fix iPad Layout

In the landscape for iPad & iPhone 6Plus layout, every time I clicked on a cell of some of the data, it segues to the detailVC on the left side, but the right side where the original detailVC remains empty.

Switch from Alamofire custom response serializers to simpler flatMap version

Like so:

class func fetchTodos(completionHandler: (Result<[Todo], NSError>) -> Void) {
    let todosEndpoint: String = "http://jsonplaceholder.typicode.com/todos/"
    Alamofire.request(.GET, todosEndpoint)
      .responseJSON { response in
        // check for errors, tell caller if needed
        guard response.result.error == nil else {
          completionHandler(.Failure(response.result.error!))
          return
        }

        // make sure we got data & it's valid JSON
        guard let value = response.result.value else {
          let failureReason = "Could not get or serialize JSON for Todos"
          let error = Error.errorWithCode(.JSONSerializationFailed, failureReason: failureReason)
          completionHandler(.Failure(error))
          return
        }

        // Make sure the JSON is an array, like we expect (and not a dictioanry)
        guard let jsonTodosArray = value as? [[String: AnyObject]] else {
          let failureReason = "Todos not parsed as expected array"
          let error = Error.errorWithCode(.JSONSerializationFailed, failureReason: failureReason)
          completionHandler(.Failure(error))
          return
        }

        // Turn the JSON array into an array of Swift objects
        // assumes we have a Todo class with an initializer that takes a jsonArray
        let todosArray = jsonTodosArray.flatMap { Todo(jsonArray: $0) }

        // hand the array of Todos back to the caller
        completionHandler(.Success(todosArray))
      }
  }

Consider removing SwiftyJSON in next edition

JSON parsing is well encapsulated and the object model in the app matches the data source fairly well, so there's not a ton of value to SwiftyJSON, unless I start using the error checking more.

Locksmith.loadDataForUserAccount - error if no data

this part of the GitHubAPIManager seems to error if there is no data already in the keychain:

get { // try to load from keychain Locksmith.loadDataForUserAccount("github") let dictionary = Locksmith.loadDataForUserAccount("github") return dictionary?["token"] as? String }

the Locksmith function performSecureStorageAction throws an error - NotFound.

however Locksmith.loadDataForUserAccount doesn't itself throw errors, so how to tell if it already exists ? Apologies if this is really a Locksmith problem..

Stop unstarred gists recording error from 404 in log

Q> I keep getting this error on the console - Error Domain=com.alamofire.error Code=-6003 "Response status code was unacceptable: 404" UserInfo={StatusCode=404, NSLocalizedFailureReason=Response status code was unacceptable: 404} when the data is loaded to the table.
Tried to search, but not sure how to fix it.

A> There’s a generic log statement in the code that checks if a gist is starred. But the correct response from the API in that case is a 404: https://developer.github.com/v3/gists/#check-if-a-gist-is-starred
I should remove the log statement but I wanted it there in case of generic errors. It should be improved so it ignores 404’s but logs other errors for that call.

Cell height constraints warning with XLForm

// Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.

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.