title: Mantle - Transform a Nested Model in Swift
body: <p>I am having a lot of trouble de-serializing and serializing a nested model in Swift using Mantle. I believe I have everything set up correctly, but I can't even get past the compilation errors. To give some perspective, I have successfully transformed classes that do not have nested model objects. Here's my class:</p>
  
  <pre><code>class TheClass : MTLModel, MTLJSONSerializing
  {
      var person:Person?
  
      static func JSONKeyPathsByPropertyKey() -&gt; [NSObject : AnyObject]!
      {
          return ["person" : "person"]
      }
  
      static func personJSONTransformer() -&gt; NSValueTransformer!
      {
          return MTLValueTransformer.reversibleTransformerWithForwardBlock(
          { (person:[NSObject : AnyObject]!) -&gt; AnyObject! in
              do
              {
                  return MTLJSONAdapter.modelOfClass(Person.self, fromJSONDictionary: person)
              }
              catch
              {
                  return Person()
              }
          },
          reverseBlock:
          { (person:Person) -&gt; AnyObject! in
              return MTLJSONAdapter.JSONDictionaryFromModel(person)
          })
      }
  }
  </code></pre>
  
  <p>This code will not compile, and I can't get it to compile. Here is the error message I am receiving:</p>
  
  <pre><code>Cannot convert return expression of type 'AnyObject!' to expected return type 'Person'
  </code></pre>
  
  <p>I've tried changing the return type of the reverse block to <code>Person</code> and <code>Person!</code>, but I get the same error message. I've been struggling with this for quite some time and could not find a working example in Swift, so any help would be greatly appreciated.</p>