Skip to content

Commit eb27dfb

Browse files
author
Rafael da Silva Ferreira
committed
Separate Mappable from ImmutableMappable
To each one of them implement one way of `init?(fromFileName file: String)`.
1 parent ea3628e commit eb27dfb

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

JSONStub.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'JSONStub'
11-
s.version = '0.1.2'
11+
s.version = '0.1.3'
1212
s.summary = 'Use JSONStub to easily load JSON files into your Mappable objects.'
1313

1414
# This description is used to generate tags and improve search results.

JSONStub/Classes/BaseMappable.swift

-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ import struct Foundation.Data
1010
import protocol ObjectMapper.BaseMappable
1111

1212
public extension BaseMappable {
13-
init?(fromFileName file: String) {
14-
guard let json = file.fileDictionary() else { return nil }
15-
16-
self.init(JSON: json)
17-
}
18-
19-
init?(fromStub stub: FileStub) {
20-
self.init(fromFileName: stub.fileName)
21-
}
22-
2313
var asData: Data {
2414
guard let json = toJSONString(), let data = json.data(using: .utf8), json != "{}" else { return Data() }
2515

JSONStub/Classes/ImmutableMappable.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
import protocol ObjectMapper.ImmutableMappable
1010

1111
public extension ImmutableMappable {
12-
init?(fromFileName file: String) {
12+
init?(fromFileName file: String) throws {
1313
guard let json = file.fileDictionary() else { return nil }
1414

15+
try self.init(JSON: json)
16+
}
17+
18+
init?(fromStub stub: FileStub) {
1519
do {
16-
try self.init(JSON: json)
20+
try self.init(fromFileName: stub.fileName)
1721
} catch {
1822
return nil
1923
}

JSONStub/Classes/Mappable.swift

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Mappable.swift
3+
// Pods
4+
//
5+
// Created by Rafael Ferreira on 3/30/17.
6+
//
7+
//
8+
9+
import protocol ObjectMapper.Mappable
10+
11+
extension Mappable {
12+
init?(fromFileName file: String) {
13+
guard let json = file.fileDictionary() else { return nil }
14+
15+
self.init(JSON: json)
16+
}
17+
18+
init?(fromStub stub: FileStub) {
19+
self.init(fromFileName: stub.fileName)
20+
}
21+
}

0 commit comments

Comments
 (0)