|
@@ -240,10 +240,10 @@ typealias KMPreference = KMPreferenceManager
|
|
|
if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
|
|
|
info = self.getDefaultInfo()
|
|
|
} else {
|
|
|
- info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as! [String : Any])
|
|
|
+ info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]) ?? [:]
|
|
|
}
|
|
|
|
|
|
- var groupInfo: [String : Any] = info![group.rawValue] as! [String : Any]
|
|
|
+ var groupInfo: [String : Any] = info?[group.rawValue] as? [String : Any] ?? [:]
|
|
|
groupInfo.updateValue(data, forKey: key)
|
|
|
|
|
|
info?.updateValue(groupInfo, forKey: group.rawValue)
|
|
@@ -265,10 +265,10 @@ typealias KMPreference = KMPreferenceManager
|
|
|
if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
|
|
|
info = self.getDefaultInfo()
|
|
|
} else {
|
|
|
- info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as! [String : Any])
|
|
|
+ info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]) ?? [:]
|
|
|
}
|
|
|
|
|
|
- let groupInfo: [String : Any] = info![findGroup(forKey: key).rawValue] as! [String : Any]
|
|
|
+ let groupInfo: [String : Any] = info?[findGroup(forKey: key).rawValue] as? [String : Any] ?? [:]
|
|
|
return groupInfo[key] as Any
|
|
|
}
|
|
|
|
|
@@ -277,7 +277,7 @@ typealias KMPreference = KMPreferenceManager
|
|
|
if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
|
|
|
info = self.getDefaultInfo()
|
|
|
} else {
|
|
|
- info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as! [String : Any])
|
|
|
+ info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]) ?? [:]
|
|
|
}
|
|
|
|
|
|
let groupInfo = self.getDefaultInfo()[group.rawValue]
|
|
@@ -779,7 +779,7 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var openLastUnlockedDocumentWhenAppStart: Bool {
|
|
|
get {
|
|
|
- return self.getData(forKey: KMOpenLastUnlockedDocumentWhenAppStartKey) as! Bool
|
|
|
+ return self.getData(forKey: KMOpenLastUnlockedDocumentWhenAppStartKey) as? Bool ?? true
|
|
|
}
|
|
|
set {
|
|
|
let _ = self.setData(data: newValue, forKey: KMOpenLastUnlockedDocumentWhenAppStartKey)
|
|
@@ -788,7 +788,7 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var documentMaximunDisplayNumber: Int {
|
|
|
get {
|
|
|
- return self.getData(forKey: KMDocumentMaximunDisplayNumberKey) as! Int
|
|
|
+ return self.getData(forKey: KMDocumentMaximunDisplayNumberKey) as? Int ?? 10
|
|
|
}
|
|
|
set {
|
|
|
let _ = self.setData(data: newValue, forKey: KMDocumentMaximunDisplayNumberKey)
|
|
@@ -797,7 +797,7 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var autoSave: Bool {
|
|
|
get {
|
|
|
- return self.getData(forKey: KMAutoSaveKey) as! Bool
|
|
|
+ return self.getData(forKey: KMAutoSaveKey) as? Bool ?? true
|
|
|
}
|
|
|
set {
|
|
|
let _ = self.setData(data: newValue, forKey: KMAutoSaveKey)
|
|
@@ -806,7 +806,7 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var autoSavePerNumberMinute: Int {
|
|
|
get {
|
|
|
- return self.getData(forKey: KMAutoSavePerNumberMinuteKey) as! Int
|
|
|
+ return self.getData(forKey: KMAutoSavePerNumberMinuteKey) as? Int ?? 5
|
|
|
}
|
|
|
set {
|
|
|
let _ = self.setData(data: newValue, forKey: KMAutoSavePerNumberMinuteKey)
|
|
@@ -815,9 +815,10 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var closeFilePromptType: KMPreferenceCloseFilePromptType {
|
|
|
get {
|
|
|
- let type: Int? = self.getData(forKey: KMCloseFilePromptTypeKey) as? Int
|
|
|
- if (type != nil && type! == 1) { // 无提示,直接保存
|
|
|
- return .noPromp
|
|
|
+ if let type = self.getData(forKey: KMCloseFilePromptTypeKey) as? Int {
|
|
|
+ if type == 1 { // 无提示,直接保存
|
|
|
+ return .noPromp
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return .promp
|
|
@@ -831,7 +832,7 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var openImageFileType: Int {
|
|
|
get {
|
|
|
- return self.getData(forKey: KMOpenImageFileTypeKey) as! Int
|
|
|
+ return self.getData(forKey: KMOpenImageFileTypeKey) as? Int ?? 0
|
|
|
}
|
|
|
set {
|
|
|
let _ = self.setData(data: newValue, forKey: KMOpenImageFileTypeKey)
|
|
@@ -841,7 +842,6 @@ extension KMPreferenceManager {
|
|
|
var author: String {
|
|
|
get {
|
|
|
return KMDataManager.ud_string(forKey: KMUserNameKey) ?? NSFullUserName()
|
|
|
-// return self.getData(forKey: KMGeneralAuthorNameKey) as! String
|
|
|
}
|
|
|
set {
|
|
|
self._syncDataToUserDefault(newValue, forKey: KMGeneralAuthorNameKey)
|
|
@@ -851,7 +851,7 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var setDefaultPDFReader: Bool {
|
|
|
get {
|
|
|
- return self.getData(forKey: KMSetDefaultPDFReaderKey) as! Bool
|
|
|
+ return self.getData(forKey: KMSetDefaultPDFReaderKey) as? Bool ?? true
|
|
|
}
|
|
|
set {
|
|
|
let result = KMTools.setDefaultPDFReader(newValue)
|
|
@@ -863,18 +863,6 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var savePasswordType: KMPreferenceSavePasswordType {
|
|
|
get {
|
|
|
-// let type: Int? = self.getData(forKey: KMSavePasswordTypeKey) as? Int
|
|
|
-// if (type == nil || type! == 2) {
|
|
|
-// return .ask
|
|
|
-// }
|
|
|
-// if (type! == 0) {
|
|
|
-// return .always
|
|
|
-// } else if (type! == 1) {
|
|
|
-// return .never
|
|
|
-// }
|
|
|
-//
|
|
|
-// return .ask
|
|
|
-
|
|
|
let type = KMDataManager.ud_integer(forKey: KMSavePasswordOptionKey)
|
|
|
if type == -1 {
|
|
|
return .ask
|
|
@@ -1022,22 +1010,21 @@ extension KMPreferenceManager {
|
|
|
extension KMPreferenceManager {
|
|
|
var viewPageDisplayType: KMPDFDisplayType {
|
|
|
get {
|
|
|
- let type: Int? = self.getData(forKey: KMViewPageDisplayTypeKey) as? Int
|
|
|
- if (type == nil || type == 1) {
|
|
|
- return .singlePageContinuous
|
|
|
- }
|
|
|
- if (type! == 0) {
|
|
|
- return .singlePage
|
|
|
- } else if (type! == 2) {
|
|
|
- return .twoUp
|
|
|
- } else if (type! == 3) {
|
|
|
- return .twoUpContinuous
|
|
|
- } else if (type! == 4) {
|
|
|
- return .bookMode
|
|
|
- } else if (type! == 5) {
|
|
|
- return .bookContinuous
|
|
|
+ if let type = self.getData(forKey: KMViewPageDisplayTypeKey) as? Int {
|
|
|
+ if (type == 0) {
|
|
|
+ return .singlePage
|
|
|
+ } else if type == 1 {
|
|
|
+ return .singlePageContinuous
|
|
|
+ } else if (type == 2) {
|
|
|
+ return .twoUp
|
|
|
+ } else if (type == 3) {
|
|
|
+ return .twoUpContinuous
|
|
|
+ } else if (type == 4) {
|
|
|
+ return .bookMode
|
|
|
+ } else if (type == 5) {
|
|
|
+ return .bookContinuous
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
return .singlePageContinuous
|
|
|
}
|
|
|
set {
|
|
@@ -1050,13 +1037,14 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var viewZoomScaleType: KMPDFZoomType {
|
|
|
get {
|
|
|
- let type: Int? = self.getData(forKey: KMViewZoomScaleTypeKey) as? Int
|
|
|
- if (type == nil || type! == 0) {
|
|
|
- return .width
|
|
|
- } else if (type! == 1) {
|
|
|
- return .fit
|
|
|
- } else if (type! == 2) {
|
|
|
- return .actualSize
|
|
|
+ if let type = self.getData(forKey: KMViewZoomScaleTypeKey) as? Int {
|
|
|
+ if (type == 0) {
|
|
|
+ return .width
|
|
|
+ } else if (type == 1) {
|
|
|
+ return .fit
|
|
|
+ } else if (type == 2) {
|
|
|
+ return .actualSize
|
|
|
+ }
|
|
|
}
|
|
|
return .width
|
|
|
}
|
|
@@ -1069,13 +1057,14 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var leftSideDisplayType: KMPreferenceLeftSideDisplayType {
|
|
|
get {
|
|
|
- let type: Int? = self.getData(forKey: KMLeftSideDisplayTypeKey) as? Int
|
|
|
- if (type == nil || type! == 0) {
|
|
|
- return .closeWhenOpenFile
|
|
|
- } else if (type! == 1) {
|
|
|
- return .openAppSaveLastSelect
|
|
|
- } else if (type! == 2) {
|
|
|
- return .showOutlineIfHas
|
|
|
+ if let type = self.getData(forKey: KMLeftSideDisplayTypeKey) as? Int {
|
|
|
+ if type == 0 {
|
|
|
+ return .closeWhenOpenFile
|
|
|
+ } else if (type == 1) {
|
|
|
+ return .openAppSaveLastSelect
|
|
|
+ } else if (type == 2) {
|
|
|
+ return .showOutlineIfHas
|
|
|
+ }
|
|
|
}
|
|
|
return .closeWhenOpenFile
|
|
|
}
|
|
@@ -1086,31 +1075,14 @@ extension KMPreferenceManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// var showOutlineList: Bool {
|
|
|
-// get {
|
|
|
-// return self.getData(forKey: KMShowOutlineListKey) as! Bool
|
|
|
-// }
|
|
|
-// set {
|
|
|
-// let _ = self.setData(data: newValue, forKey: KMShowOutlineListKey)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// var leftSideExpandType: Int {
|
|
|
-// get {
|
|
|
-// return self.getData(forKey: KMLeftSideExpandTypeKey) as! Int
|
|
|
-// }
|
|
|
-// set {
|
|
|
-// let _ = self.setData(data: newValue, forKey: KMLeftSideExpandTypeKey)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
var propertyPanelExpandType: KMPreferencePropertyPanelExpandType {
|
|
|
get {
|
|
|
- let type: Int? = self.getData(forKey: KMPropertyPanelExpandTypeKey) as? Int
|
|
|
- if (type == nil || type! == 0) {
|
|
|
- return .auto
|
|
|
- } else if (type! == 1) {
|
|
|
- return .manual
|
|
|
+ if let type = self.getData(forKey: KMPropertyPanelExpandTypeKey) as? Int {
|
|
|
+ if (type == 0) {
|
|
|
+ return .auto
|
|
|
+ } else if (type == 1) {
|
|
|
+ return .manual
|
|
|
+ }
|
|
|
}
|
|
|
return .auto
|
|
|
}
|
|
@@ -1123,7 +1095,7 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var highlightForms: Bool {
|
|
|
get {
|
|
|
- return self.getData(forKey: KMHighlightFormsKey) as! Bool
|
|
|
+ return self.getData(forKey: KMHighlightFormsKey) as? Bool ?? true
|
|
|
}
|
|
|
set {
|
|
|
let _ = self.setData(data: newValue, forKey: KMHighlightFormsKey)
|
|
@@ -1132,13 +1104,14 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var pageIndicatorType: KMPreferencePageIndicatorDisplayType {
|
|
|
get {
|
|
|
- let type: Int? = self.getData(forKey: KMPageIndicatorTypeKey) as? Int
|
|
|
- if (type == nil || type! == 2) {
|
|
|
- return .never
|
|
|
- } else if (type! == 0) {
|
|
|
- return .automatic
|
|
|
- } else if (type! == 1) {
|
|
|
- return .always
|
|
|
+ if let type = self.getData(forKey: KMPageIndicatorTypeKey) as? Int {
|
|
|
+ if (type == 2) {
|
|
|
+ return .never
|
|
|
+ } else if (type == 0) {
|
|
|
+ return .automatic
|
|
|
+ } else if (type == 1) {
|
|
|
+ return .always
|
|
|
+ }
|
|
|
}
|
|
|
return .never
|
|
|
}
|
|
@@ -1151,7 +1124,7 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var highlightLinks: Bool {
|
|
|
get {
|
|
|
- return self.getData(forKey: KMHighlightLinksKey) as! Bool
|
|
|
+ return self.getData(forKey: KMHighlightLinksKey) as? Bool ?? true
|
|
|
}
|
|
|
set {
|
|
|
let _ = self.setData(data: newValue, forKey: KMHighlightLinksKey)
|
|
@@ -1786,12 +1759,10 @@ extension KMPreferenceManager {
|
|
|
extension KMPreferenceManager {
|
|
|
var markupFontTextString: String {
|
|
|
get {
|
|
|
- let string: String? = UserDefaults.standard.object(forKey: CFreeTextNoteFontNameKey) as? String
|
|
|
- if (string == nil) {
|
|
|
- return KMDefaultFontName
|
|
|
- }
|
|
|
- if (KMPreferenceManager.supportFonts.contains(string!)) {
|
|
|
- return string!
|
|
|
+ if let string = UserDefaults.standard.object(forKey: CFreeTextNoteFontNameKey) as? String {
|
|
|
+ if (KMPreferenceManager.supportFonts.contains(string)) {
|
|
|
+ return string
|
|
|
+ }
|
|
|
}
|
|
|
return KMDefaultFontName
|
|
|
}
|
|
@@ -1807,12 +1778,9 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var markupFontTextAligment: NSTextAlignment {
|
|
|
get {
|
|
|
- let type: Int? = UserDefaults.standard.integer(forKey: CFreeTextNoteAlignmentKey)
|
|
|
- if (type == nil) {
|
|
|
- return .left
|
|
|
- }
|
|
|
- if (type! == 0 || type! == 1 || type == 2) {
|
|
|
- return NSTextAlignment(rawValue: type!)!
|
|
|
+ let type = UserDefaults.standard.integer(forKey: CFreeTextNoteAlignmentKey)
|
|
|
+ if (type == 0 || type == 1 || type == 2) {
|
|
|
+ return NSTextAlignment(rawValue: type) ?? .left
|
|
|
}
|
|
|
return .left
|
|
|
}
|
|
@@ -1828,12 +1796,10 @@ extension KMPreferenceManager {
|
|
|
|
|
|
var markupFontNoteString: String {
|
|
|
get {
|
|
|
- let fontName: String? = KMPreferenceManager.shared.getData(forKey: KMPreference.markupFontNoteStringKey) as? String
|
|
|
- if (fontName == nil) {
|
|
|
- return KMDefaultFontName
|
|
|
- }
|
|
|
- if (KMPreference.supportFonts.contains(fontName!)) {
|
|
|
- return fontName!
|
|
|
+ if let fontName = KMPreferenceManager.shared.getData(forKey: KMPreference.markupFontNoteStringKey) as? String {
|
|
|
+ if (KMPreference.supportFonts.contains(fontName)) {
|
|
|
+ return fontName
|
|
|
+ }
|
|
|
}
|
|
|
return KMDefaultFontName
|
|
|
}
|
|
@@ -1867,29 +1833,53 @@ extension KMPreferenceManager {
|
|
|
|
|
|
private func syncDataToPDFView(_ data: Any, forKey key: KMPreferenceKey) {
|
|
|
if (key == KMMarkupColorHighlightKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CHighlightNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CHighlightNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorUnderlineKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CUnderlineNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CUnderlineNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorStrikthroughKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CStrikeOutNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CStrikeOutNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorPenKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CInkNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CInkNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorNoteKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CAnchoredNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CAnchoredNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorRectangleFillKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CSquareNoteInteriorColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CSquareNoteInteriorColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorRectangleBorderKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CSquareNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CSquareNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorCircleFillKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CCircleNoteInteriorColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CCircleNoteInteriorColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorCircleBorderKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CCircleNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CCircleNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorLineKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CLineNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CLineNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorArrowKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CArrowNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CArrowNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupColorTextKey) {
|
|
|
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CFreeTextNoteColorKey)
|
|
|
+ if let color = data as? NSColor {
|
|
|
+ UserDefaults.standard.setPDFListViewColor(color, forKey: CFreeTextNoteColorKey)
|
|
|
+ }
|
|
|
} else if (key == KMMarkupFontTextStringKey) {
|
|
|
UserDefaults.standard.set(data, forKey: CFreeTextNoteFontNameKey)
|
|
|
UserDefaults.standard.synchronize()
|
|
@@ -1925,22 +1915,22 @@ extension KMPreferenceManager {
|
|
|
}
|
|
|
|
|
|
private func getDefaultColors(forKey key: KMPreferenceKey) -> [Double] {
|
|
|
- let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue]!
|
|
|
+ let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue] ?? [:]
|
|
|
for key_i in [KMMarkupColorHighlightKey, KMMarkupColorUnderlineKey, KMMarkupColorStrikthroughKey,
|
|
|
KMMarkupColorPenKey, KMMarkupColorNoteKey, KMMarkupColorTextKey,
|
|
|
KMMarkupColorRectangleFillKey, KMMarkupColorRectangleBorderKey,
|
|
|
KMMarkupColorCircleFillKey, KMMarkupColorCircleBorderKey,
|
|
|
KMMarkupColorLineKey, KMMarkupColorArrowKey] {
|
|
|
if (key == key_i) {
|
|
|
- return markupGroupInfo[key] as! [Double]
|
|
|
+ return markupGroupInfo[key] as? [Double] ?? []
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- let displayGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.display.rawValue]!
|
|
|
+ let displayGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.display.rawValue] ?? [:]
|
|
|
for key_i in [KMDisplayBackgroundNormalColorKey, KMDisplayBackgroundFullScreenColorKey,
|
|
|
KMDisplayFieldHighlightingColorKey, KMDisplayRequiredFieldHighlightingColorKey] {
|
|
|
if (key == key_i) {
|
|
|
- return displayGroupInfo[key] as! [Double]
|
|
|
+ return displayGroupInfo[key] as? [Double] ?? []
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1952,14 +1942,16 @@ extension KMPreferenceManager {
|
|
|
}
|
|
|
|
|
|
private func resetDataToPDFView() {
|
|
|
- let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue]!
|
|
|
+ let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue] ?? [:]
|
|
|
// colors
|
|
|
for key in [KMMarkupColorHighlightKey, KMMarkupColorUnderlineKey, KMMarkupColorStrikthroughKey,
|
|
|
KMMarkupColorPenKey, KMMarkupColorNoteKey, KMMarkupColorTextKey,
|
|
|
KMMarkupColorRectangleFillKey, KMMarkupColorRectangleBorderKey,
|
|
|
KMMarkupColorCircleFillKey, KMMarkupColorCircleBorderKey,
|
|
|
KMMarkupColorLineKey, KMMarkupColorArrowKey] {
|
|
|
- self.syncDataToPDFView(self.dataToColor(colors: markupGroupInfo[key] as! [Double]), forKey: key)
|
|
|
+ if let data = markupGroupInfo[key] as? [Double] {
|
|
|
+ self.syncDataToPDFView(self.dataToColor(colors:data ), forKey: key)
|
|
|
+ }
|
|
|
}
|
|
|
// lines
|
|
|
for key in [KMFreeTextNoteLineStyleKey, KMFreeTextNoteLineWidthKey, KMFreeTextNoteDashPatternKey,
|
|
@@ -2069,14 +2061,12 @@ extension KMPreferenceManager {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- let viewSetting: [String : Any]? = UserDefaults.standard.value(forKey: kKMViewSettingKey) as? [String : Any]
|
|
|
+ let viewSetting: [String : Any] = UserDefaults.standard.value(forKey: kKMViewSettingKey) as? [String : Any] ?? [:]
|
|
|
var info: [String : Any] = [:]
|
|
|
- if (viewSetting != nil) {
|
|
|
- for (key, value) in viewSetting! {
|
|
|
- info.updateValue(value, forKey: key)
|
|
|
- }
|
|
|
+ for (key, value) in viewSetting {
|
|
|
+ info.updateValue(value, forKey: key)
|
|
|
}
|
|
|
- for (key, value) in newValue! {
|
|
|
+ for (key, value) in newValue ?? [:] {
|
|
|
if (key == .pageNumber) { // 只处理 枚举
|
|
|
info.updateValue(value, forKey: key.rawValue)
|
|
|
}
|