From 7df7e905f35800bc572d89ef068c02bcbdde2605 Mon Sep 17 00:00:00 2001 From: Rafael da Silva Ferreira Date: Thu, 30 Mar 2017 01:56:29 -0300 Subject: [PATCH] Refactor String extension To add fileString method that it will be in charge of return the file as string. --- JSONStub.podspec | 2 +- JSONStub/Classes/String.swift | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/JSONStub.podspec b/JSONStub.podspec index 439ebec..e7ad37a 100644 --- a/JSONStub.podspec +++ b/JSONStub.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'JSONStub' - s.version = '0.1.3' + s.version = '0.1.4' 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/String.swift b/JSONStub/Classes/String.swift index bf79566..008052b 100644 --- a/JSONStub/Classes/String.swift +++ b/JSONStub/Classes/String.swift @@ -22,6 +22,12 @@ public extension String { return json as? [String: AnyObject] } + func fileString() -> String { + guard let data = fileData(), let json = String.init(data: data, encoding: .utf8) else { return "{}" } + + return json + } + func filePath() -> String? { guard splitAtDot.count == 2 else { return nil }