Skip to content

Commit

Permalink
Remove redundant convenience initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
achan committed Nov 13, 2016
1 parent f5571f3 commit ad581ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
23 changes: 9 additions & 14 deletions FisherHall/Features/Latest Bulletin/BulletinViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,24 @@ class BulletinViewModel {
let bannerURLString: String
var serviceOrder: String

convenience init(name: String, publishedAt: NSDate, bannerURL: String? = nil, serviceOrder: String? = nil) {
let bannerOrDefault = bannerURL ?? "https://s3.amazonaws.com/mcac/app/assets/images/theme-1920-6099a636f0f320b6d38b157909e64be6.jpg"
self.init(
name: name,
publishedAt: publishedAt,
bannerURL: bannerOrDefault,
serviceOrder: serviceOrder ?? ""
)
}

init(name: String, publishedAt: NSDate, bannerURL: String, serviceOrder: String) {
init(name: String, publishedAt: NSDate, bannerURL: String? = nil, serviceOrder: String? = nil) {
self.name = name
self.publishedAt = publishedAt
self.bannerURLString = bannerURL
self.serviceOrder = serviceOrder
bannerURLString = bannerURL ?? "https://s3.amazonaws.com/mcac/app/assets/images/theme-1920-6099a636f0f320b6d38b157909e64be6.jpg"
self.serviceOrder = serviceOrder ?? ""
}

public static func fromResource(resource: BulletinResource) -> BulletinViewModel? {
guard let name = resource.name, let publishedAt = resource.publishedAt else {
return nil
}

return BulletinViewModel(name: name, publishedAt: publishedAt, bannerURL: resource.bannerUrl?.absoluteString, serviceOrder: resource.serviceOrder)
return BulletinViewModel(
name: name,
publishedAt: publishedAt,
bannerURL: resource.bannerUrl?.absoluteString,
serviceOrder: resource.serviceOrder
)
}

public func bannerURL() -> URL? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Nimble

class BulletinViewModelSpec: QuickSpec {
override func spec() {
fdescribe("fromResource") {
describe("fromResource") {
context("when resource doesn't contain required fields") {
var subject: BulletinViewModel!

Expand Down

0 comments on commit ad581ac

Please sign in to comment.