diff --git a/IosAwnCore.podspec b/IosAwnCore.podspec index 07e478c..e56316f 100644 --- a/IosAwnCore.podspec +++ b/IosAwnCore.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'IosAwnCore' - s.version = '0.7.4-pre.1' + s.version = '0.7.4-pre.2' s.summary = 'Awesome Notifications iOS Core' s.description = <<-DESC diff --git a/IosAwnCore/Classes/databases/SQLitePrimitivesDB.swift b/IosAwnCore/Classes/databases/SQLitePrimitivesDB.swift index 11fbd62..90989ef 100644 --- a/IosAwnCore/Classes/databases/SQLitePrimitivesDB.swift +++ b/IosAwnCore/Classes/databases/SQLitePrimitivesDB.swift @@ -295,8 +295,11 @@ public class SQLitePrimitivesDB { return .success((value == 1) as? T) case is String.Type: - let value = String(cString: sqlite3_column_text(statement, 0)) - return .success(value as? T) + let value = sqlite3_column_text(statement, 0) + if value != nil { + return .success(String(cString: value!) as? T) + } + return .success(nil) default: return .failure(SQLiteError.invalidParameterType) @@ -355,7 +358,9 @@ public class SQLitePrimitivesDB { defer { sqlite3_finalize(statement) } while sqlite3_step(statement) == SQLITE_ROW { - count = Int(sqlite3_column_int(statement, 0)) + let value = sqlite3_column_int(statement, 0) + if value != nil { count = Int(value) } + else { count = 0 } } return .success(count) @@ -412,10 +417,12 @@ public class SQLitePrimitivesDB { defer { sqlite3_finalize(statement) } while sqlite3_step(statement) == SQLITE_ROW { - let key = String(cString: sqlite3_column_text(statement, 0)) - let value = valueGetter(statement) - - values[key] = value + let rawValue = sqlite3_column_text(statement, 0) + if rawValue != nil { + let key = String(cString: rawValue!) + let value = valueGetter(statement) + values[key] = value + } } return .success(values) @@ -476,10 +483,12 @@ public class SQLitePrimitivesDB { defer { sqlite3_finalize(statement) } while sqlite3_step(statement) == SQLITE_ROW { - let key = String(cString: sqlite3_column_text(statement, 0)) - let value = valueGetter(statement) - - values[key] = value + let rawValue = sqlite3_column_text(statement, 0) + if rawValue != nil { + let key = String(cString: rawValue!) + let value = valueGetter(statement) + values[key] = value + } } return .success(values) diff --git a/IosAwnCore/Classes/managers/LocalizationManager.swift b/IosAwnCore/Classes/managers/LocalizationManager.swift index ff52dd1..1250e25 100644 --- a/IosAwnCore/Classes/managers/LocalizationManager.swift +++ b/IosAwnCore/Classes/managers/LocalizationManager.swift @@ -10,56 +10,29 @@ import Foundation class LocalizationManager { static let shared = LocalizationManager() + let _userDefaults = UserDefaults(suiteName: Definitions.USER_DEFAULT_TAG) + let localizationKey = "awn_localization_languageCode" + func setLocalization(languageCode: String? = nil) -> Bool { - let langCode = - languageCode ?? - Locale.preferredLanguages[0] - switch SQLitePrimitivesDB.shared.setString( - tag: "localization", - key: "languageCode", - value: langCode + guard let userDefaults = _userDefaults ?? UserDefaults(suiteName: Definitions.USER_DEFAULT_TAG) + else { return false } + + let langCode = + (languageCode ?? Locale.preferredLanguages[0]) .lowercased() .replacingOccurrences(of: "_", with: "-") - ) { - case .success(): - return true - case .failure(let error): - let awnError = ExceptionFactory.shared.createNewAwesomeException( - className: "LocalizationManager", - code: ExceptionCode.CODE_INSUFFICIENT_PERMISSIONS, - message: "SQLitePrimitivesDB is not available \(error.localizedDescription)", - detailedCode: ExceptionCode.DETAILED_INSUFFICIENT_PERMISSIONS+".setLocalization" - ) - print(awnError) - return false - } + + userDefaults.set(langCode, forKey: localizationKey) + + return true } func getLocalization() -> String { let appLangCode = Locale.preferredLanguages[0] - - switch SQLitePrimitivesDB.shared.getString( - tag: "localization", - key: "languageCode" - ) { - - case .success(let value): - return (value ?? appLangCode) - .lowercased() - .replacingOccurrences(of: "_", with: "-") - - case .failure(let error): - let error = ExceptionFactory.shared.createNewAwesomeException( - className: "LocalizationManager", - code: ExceptionCode.CODE_INSUFFICIENT_PERMISSIONS, - message: "SQLitePrimitivesDB is not available \(error.localizedDescription)", - detailedCode: ExceptionCode.DETAILED_INSUFFICIENT_PERMISSIONS+".getLocalization" - ) - print(error) - return appLangCode + let awnLangCode = _userDefaults?.string(forKey: localizationKey) + return (awnLangCode ?? appLangCode) .lowercased() .replacingOccurrences(of: "_", with: "-") - } } }