Giter Site home page Giter Site logo

exacttime's Introduction

ExactTime

An iOS demonstrating using submodules.

###Step 1:

  • Clone down this project (or create a new single view controller in Xcode)
  • Add AFNetworking as a submodule (https://github.com/AFNetworking/AFNetworking)
    • In terminal navigate to the directory of your project
    • git submodule add https://github.com/AFNetworking/AFNetworking.git External/AFNetworking
    • Note: This clones the code to our computer, we need to add it to the project
  • Add the source code in the AFNetworking folder to your app
    • Note: Do not select "Copy items into destination group's folder" - We want references, not actual copies of the files

###Step 2:

  • Use AFNetworking
  • In the viewDidLoad method create a NSURLRequest for the URL http://www.timeapi.org/utc/now
  • Initialize an AFHTTPRequestOperation with that urlrequest
  • setCompletionBlock on the request operation
  • Call start on that operation

###You just made a network request.

##AFNetworking

###Step 3: Add a NetworkController

  • Create an NSObject subclass called NetworkController
  • Add a sessionManager property @property (nonatomic, strong) AFHTTPSessionManager *sessionManager; to the interface section of the implementation file (you may have to type it up yourself.
  • Add the base URL of the new time request as a static string: NSString * const baseURL = @"http://time.jsontest.com";
  • Add an init method, and in the init method initialize the sessionManager with a default configuration and base URL.

###Step 4: Add a request method

  • Add the method - (void)getExactTimeInfo:(void (^)(NSDictionary *exactTimeInfo, NSError *error))completion; to the header file.
  • In the implementation of that method call GET on the session manager with the @"/" endpoint.

###Step 5: A simple UI

  • Add a UILabel property to the class and wire it up in your storyboard

###Step 6: Call the request method

  • In the viewDidLoad method initialize a NetworkController
  • Call the getExactTimeInfo method on the network controller
  • Set the label text to the exactTimeInfo[@"time"]

exacttime's People

Contributors

jkhowland avatar

Watchers

James Cloos avatar David Monson 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.