Skip to content

Instantly share code, notes, and snippets.

@penland365
Created May 15, 2015 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penland365/31c656645c8c749513d8 to your computer and use it in GitHub Desktop.
Save penland365/31c656645c8c749513d8 to your computer and use it in GitHub Desktop.
Swift Either for handling mock data from Remote Api
class SomeController {
private func loadOfferSummaries() -> Void {
api.fetchOfferSummaries( { either in
switch either {
case let .Failure(boxedError):
NSLog("Failure fetching games, code --> \(boxedError.value.code)")
// mock out test data
self.offers = self.mockOfferSummaries()
self.loadTable()
case let .Success(boxed):
self.offers = boxed.value
NSLog("Fetched \(self.offers.count) offer summaries from server")
self.loadTable()
}
})
}
private func mockOfferSummaries() -> OfferSummaries {
let outDeal = AirOutSummary(id: 1, deal: "Better Seat?")
let inDeal = AirInSummary(id: 2, deal: "Free Drinks?")
let hotelDeal = HotelSummary(id: 3, deal: "Nicer Room?")
return [outDeal, hotelDeal, inDeal]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment