Skip to content

Commit ea3628e

Browse files
author
Rafael da Silva Ferreira
committed
Separate customer initializers of Mappables
Separate BaseMappable from ImmutableMappable.
1 parent 82d635e commit ea3628e

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
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.1'
11+
s.version = '0.1.2'
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// Copyright © 2016 Swift Yah. All rights reserved.
77
//
88

9-
import ObjectMapper
9+
import struct Foundation.Data
10+
import protocol ObjectMapper.BaseMappable
1011

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

0 commit comments

Comments
 (0)