Created
March 21, 2018 12:15
-
-
Save dasmido/1c53ac86696606ce323a255beb5d2f24 to your computer and use it in GitHub Desktop.
NewsApi-Model-Article
This file contains hidden or 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
// | |
// Article.swift | |
// AlamofireJSON | |
// | |
// Created by Mohammed Jamal on 3/21/18. | |
// Copyright © 2018 Mohammed Jamal. All rights reserved. | |
// | |
import UIKit | |
import Alamofire | |
class Article { | |
var _title : String! | |
var _description: String! | |
var _urlToImage:String! | |
var _publishedAt: String! | |
var title : String { | |
if _title == nil { | |
_title = "" | |
} | |
return _title | |
} | |
var description : String { | |
if _description == nil { | |
_description = "" | |
} | |
return _description | |
} | |
var urlToImage : String { | |
if _urlToImage == nil { | |
_urlToImage = "" | |
} | |
return _urlToImage | |
} | |
var publishedAt : String { | |
if _publishedAt == nil { | |
_publishedAt = "" | |
} | |
return _publishedAt | |
} | |
init(articleDict: Dictionary<String, AnyObject>){ | |
if let articles = articleDict["articles"] as? [Dictionary<String, AnyObject>]{ | |
if let title = articles[0]["title"] as? String { | |
self._title = title.capitalized | |
print("title: \(self._title)") | |
} | |
if let description = articles[0]["description"] as? String { | |
self._description = description.capitalized | |
print("description: \(self._description)") | |
} | |
if let urlToImage = articles[0]["urlToImage"] as? String { | |
self._urlToImage = urlToImage | |
print("urlToImage: \(self._urlToImage)") | |
} | |
if let publishedAt = articles[0]["publishedAt"] as? String { | |
self._publishedAt = publishedAt | |
print("publishedAt: \(self._publishedAt)") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment