Fix UInt conversion

This commit is contained in:
1024jp 2016-10-15 14:55:04 +09:00
parent d44179acae
commit 566fdfea44
3 changed files with 4 additions and 2 deletions

View File

@ -11,6 +11,7 @@ develop
- Fix an issue where new syntax style could't be created.
- Fix an issue where new value of last edited text field in preferences was occasionally discarded.
- Fix a possible crash on application termination.
- Fix a possible crash on opening document.
- Fix error message of syntax style valitation.

View File

@ -82,7 +82,7 @@ extension UserDefaults {
subscript(key: DefaultKey<UInt>) -> UInt {
get { return UInt(self.integer(forKey: key.rawValue)) }
get { return UInt(exactly: self.integer(forKey: key.rawValue)) ?? 0 }
set { self.set(newValue, forKey: key.rawValue) }
}

View File

@ -104,7 +104,8 @@ final class Document: NSDocument, AdditionalDocumentPreparing, EncodingHolder {
let uuid = UUID().uuidString
self.autosaveIdentifier = uuid.substring(to: uuid.index(uuid.startIndex, offsetBy: UniqueFileIDLength))
self.encoding = String.Encoding(rawValue: Defaults[.encodingInNew])
let encoding = String.Encoding(rawValue: Defaults[.encodingInNew])
self.encoding = String.availableStringEncodings.contains(encoding) ? encoding : .utf8
if self.encoding == .utf8 {
self.hasUTF8BOM = Defaults[.saveUTF8BOM]
}