diff --git a/JSONStub.podspec b/JSONStub.podspec index 0734c8f..439ebec 100644 --- a/JSONStub.podspec +++ b/JSONStub.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'JSONStub' - s.version = '0.1.2' + s.version = '0.1.3' s.summary = 'Use JSONStub to easily load JSON files into your Mappable objects.' # This description is used to generate tags and improve search results. diff --git a/JSONStub/Classes/BaseMappable.swift b/JSONStub/Classes/BaseMappable.swift index 2476d45..6a00931 100644 --- a/JSONStub/Classes/BaseMappable.swift +++ b/JSONStub/Classes/BaseMappable.swift @@ -10,16 +10,6 @@ import struct Foundation.Data import protocol ObjectMapper.BaseMappable public extension BaseMappable { - init?(fromFileName file: String) { - guard let json = file.fileDictionary() else { return nil } - - self.init(JSON: json) - } - - init?(fromStub stub: FileStub) { - self.init(fromFileName: stub.fileName) - } - var asData: Data { guard let json = toJSONString(), let data = json.data(using: .utf8), json != "{}" else { return Data() } diff --git a/JSONStub/Classes/ImmutableMappable.swift b/JSONStub/Classes/ImmutableMappable.swift index 242d2be..f48b428 100644 --- a/JSONStub/Classes/ImmutableMappable.swift +++ b/JSONStub/Classes/ImmutableMappable.swift @@ -9,11 +9,15 @@ import protocol ObjectMapper.ImmutableMappable public extension ImmutableMappable { - init?(fromFileName file: String) { + init?(fromFileName file: String) throws { guard let json = file.fileDictionary() else { return nil } + try self.init(JSON: json) + } + + init?(fromStub stub: FileStub) { do { - try self.init(JSON: json) + try self.init(fromFileName: stub.fileName) } catch { return nil } diff --git a/JSONStub/Classes/Mappable.swift b/JSONStub/Classes/Mappable.swift new file mode 100644 index 0000000..fd4230a --- /dev/null +++ b/JSONStub/Classes/Mappable.swift @@ -0,0 +1,21 @@ +// +// Mappable.swift +// Pods +// +// Created by Rafael Ferreira on 3/30/17. +// +// + +import protocol ObjectMapper.Mappable + +extension Mappable { + init?(fromFileName file: String) { + guard let json = file.fileDictionary() else { return nil } + + self.init(JSON: json) + } + + init?(fromStub stub: FileStub) { + self.init(fromFileName: stub.fileName) + } +}