Skip to content

Instantly share code, notes, and snippets.

View rinold's full-sized avatar

Mikhail Churbanov rinold

  • Russian Federation
View GitHub Profile
import XCTest
protocol ApiForMocking {
func testFunc1()
func testFunc2()
func testFunc3()
}
class ApiMock: ApiForMocking {
@rinold
rinold / gist:120eefe1e4e5d0f9da5e106120f72216
Created December 29, 2017 15:35
swift-4-how-to-implement-codable-protocol-for-json-array-of-different-types
import Foundation
let dataString = "{ \"materials\": [ { \"reflection\": { \"title\": \"3-2-1 reflection\", \"description\": \"please reflect after today\", \"questions\": [ { \"question\": \"question 1\", \"answer\": \"answer 1\", \"answerImageUrl\": \"http://xxx\" }, { \"question\": \"question 1\", \"answer\": \"answer 1\", \"answerImageUrl\": \"http://xxx\" } ] } }, { \"video\": { \"title\": \"the jungle\", \"description\": \"please watch after today lesson\", \"videoUrl\": \"http://\" } }, { \"note\": { \"title\": \"the note\", \"description\": \"please read after today lesson\" } } ]}"
let data = dataString.data(using: .utf8)!
struct Response: Codable {
let materials: [Material]
}
enum Material: Codable {