From d8c32293946a203804a6a08aa0fc61c35b32ad32 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 14 Feb 2022 12:31:08 -0400 Subject: [PATCH] Prettify Document.getChunkFilename --- SilicaViewer/Document.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/SilicaViewer/Document.swift b/SilicaViewer/Document.swift index 95a12b8..797a241 100644 --- a/SilicaViewer/Document.swift +++ b/SilicaViewer/Document.swift @@ -133,17 +133,14 @@ class Document: NSDocument { } /* - Parses the chunk filename, ex. 1~1 to integer coordinates. + Parses the chunk filename, ex. "1~1.chunk" to integer coordinates (1, 2). */ func parseChunkFilename(_ filename: String) -> (Int, Int)? { let pathURL = URL(fileURLWithPath: filename) let pathComponents = pathURL.lastPathComponent.replacingOccurrences(of: ".chunk", with: "").components(separatedBy: "~") - let x = Int(pathComponents[0]) - let y = Int(pathComponents[1]) - - if x != nil && y != nil { - return (x!, y! + 1) + if let x = Int(pathComponents[0]), let y = Int(pathComponents[1]) { + return (x, y + 1) } else { return nil }