From cbc0df164b89c6d59d7c0437a77966163ec79c84 Mon Sep 17 00:00:00 2001 From: Edwin Vermeer Date: Sat, 28 Nov 2015 14:02:01 +0100 Subject: [PATCH] updated readme --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index c9bf7d99..c54727dc 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,38 @@ public class TestObject6: EVObject { } ``` +### What to do when you use object enheritance +You can deserialize json to an object that uses enheritance. When the properties are specified as the base class, then the correct specific object type will be returned by the function getSecificType. See the sample code below or the unit test in EVReflectionEnheritanceTests.swift + +``` +class Quz: EVObject { + var fooArray: Array = [] + var fooBar: Foo? + var fooBaz: Foo? +} + +class Foo: EVObject { + var allFoo: String = "all Foo" + + // What you need to do to get the correct type for when you deserialize enherited classes + override func getSpecificType(dict: NSDictionary) -> EVObject { + if dict["justBar"] != nil { + return Bar() + } else if dict["justBaz"] != nil { + return Baz() + } + return self + } +} + +class Bar : Foo { + var justBar: String = "For bar only" +} + +class Baz: Foo { + var justBaz: String = "For baz only" +} +``` ### When to use EVObject instead of NSObject as a base class.