From 5eb55520a4f6a4cdaedc8606968b3a7ba186e251 Mon Sep 17 00:00:00 2001 From: Aubrey Goodman Date: Mon, 9 Oct 2017 19:14:26 -0700 Subject: [PATCH] Fix force-unwrapped URL assumption Force-unwrapping the URL should be fine, but if for some reason it is not, this will crash any app using the framework. This change allows for graceful degradation, in such a case. --- IPAPI/IPAPI.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/IPAPI/IPAPI.swift b/IPAPI/IPAPI.swift index 7a36e5e..f15d4f6 100644 --- a/IPAPI/IPAPI.swift +++ b/IPAPI/IPAPI.swift @@ -19,7 +19,10 @@ open class IPAPI { fileprivate static let endpointUrl = "http://ip-api.com/json" open class func location(_ session: URLSession) -> Observable { - let url = URL(string: endpointUrl)! + guard let url: URL = URL(string: endpointUrl) else { + return Observable.just(nil) + } + return session.rx .json(url: url) .observeOn(MainScheduler.asyncInstance)