Last active
August 29, 2015 14:22
-
-
Save NicholasTD07/5320dbb9c5613bb9398b to your computer and use it in GitHub Desktop.
Argo doesn't work with subclass (Swift 1.2 AND 2.0)
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
import XCTest | |
import Argo | |
import Runes | |
class SuperClass { | |
let something: String | |
init(something: String) { | |
self.something = something | |
} | |
} | |
extension SuperClass: Decodable { | |
static func create(something: String) -> SuperClass { | |
return SuperClass(something: something) | |
} | |
static func decode(j: JSON) -> Decoded<SuperClass> { | |
return SuperClass.create | |
<^> j <| "something" | |
} | |
} | |
class SubClass: SuperClass { | |
let someOtherThing: String | |
init(something: String, someOtherThing: String) { | |
self.someOtherThing = someOtherThing | |
super.init(something: something) | |
} | |
} | |
//extension SubClass: Decodable { | |
// ERROR in the line above: | |
// * Swift 1.2: Type 'SubClass' does not conform to protocol 'Decodable' | |
// * Swift 2.0: Redundant conformance of 'SubClass' to protocol 'Decodable' | |
extension SubClass { | |
static func create(something: String)(someOtherThing: String) -> SubClass { | |
return SubClass(something: something, someOtherThing: someOtherThing) | |
} | |
static func decode(j: JSON) -> Decoded<SubClass> { | |
return SubClass.create | |
<^> j <| "something" | |
<*> j <| "some_other_thing" | |
} | |
} | |
class DecodingTests: XCTestCase { | |
func testDecodingSuperClass() { | |
let model: SuperClass? = JSONFromFile("super_class") >>- decode | |
XCTAssert(model != nil) | |
XCTAssert(model?.something == "Something") | |
} | |
func testDecodingSubClass() { | |
// ERROR in the line below comments | |
// for both Swift 1.2 and 2.0: | |
// Could not find an overload that accepts the supplied argument | |
let model: SubClass? = JSONFromFile("sub_class") >>- decode | |
XCTAssert(model != nil) | |
XCTAssert(model?.something == "Something") | |
XCTAssert(model?.someOtherThing == "Some other thing") | |
} | |
} |
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
{ | |
"something": "Something", | |
"some_other_thing": "Some other thing" | |
} |
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
{ | |
"something": "Something" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment