guard all the things! 👮

This commit is contained in:
Olivier Halligon
2015-10-18 06:57:41 +02:00
parent f0abd34c32
commit f4ed872a45
4 changed files with 58 additions and 62 deletions

View File

@@ -9,11 +9,11 @@ public class Template {
/// Create a template with the given name inside the given bundle
public convenience init(named:String, inBundle bundle:NSBundle? = nil) throws {
let useBundle = bundle ?? NSBundle.mainBundle()
if let url = useBundle.URLForResource(named, withExtension: nil) {
try self.init(URL:url)
} else {
guard let url = useBundle.URLForResource(named, withExtension: nil) else {
throw NSError(domain: NSCocoaErrorDomain, code: NSFileNoSuchFileError, userInfo: nil)
}
try self.init(URL:url)
}
/// Create a template with a file found at the given URL