Created
May 6, 2015 19:48
-
-
Save jshawl/36e7b88c784c45113889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Story.swift | |
// MashItUp | |
// | |
// Created by Jesse Shawl on 5/5/15. | |
// Copyright (c) 2015 Jesse Shawl. All rights reserved. | |
// | |
import UIKit | |
class Story: NSObject { | |
let identifier: String? | |
let title: String? | |
let author: String? | |
let postDate: NSDate? | |
let link: NSURL? | |
let excerpt: String? | |
let channel: String? | |
init(dictionary:[String:AnyObject]){ | |
identifier = dictionary["_id"] as? String | |
title = dictionary["title"] as? String | |
author = dictionary["author"] as? String | |
postDate = NSDate() | |
link = NSURL(string: dictionary["link"] as String) | |
excerpt = dictionary["excerpt"] as? NSString | |
channel = dictionary["channel"] as? NSString | |
} | |
} | |
class Provider { | |
func getAllStories(){ | |
let session = NSURLSession.sharedSession() | |
let url = NSURL(string:"http://mashable.com/stories.json")! | |
let task = session.dataTaskWithURL(url) { (data, response, error) in | |
var error:NSError? = nil | |
let object = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: &error) as [String:AnyObject] | |
self.createStories( object ) | |
} | |
task.resume() | |
} | |
func createStories( dictionary:[String:AnyObject] ) { | |
if let newStories = dictionary["new"] as? [[String:AnyObject]]{ | |
for story in newStories{ | |
let story = Story( dictionary: story ) | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment