From 0d4632913f2c867c59d14ce176043babe0cf2247 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Sun, 11 Sep 2016 10:41:48 -0400 Subject: [PATCH] Coredata def modenerization --- .../Library/CloudBooksController.swift | 3 +-- .../Library/LanguageFilterController.swift | 6 +++--- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOSWidgets/Bookmarks/Info.plist | 2 +- Kiwix.xcodeproj/project.pbxproj | 20 ++++++++++++++++--- .../Classes/Language+CoreDataProperties.swift | 6 +++--- Kiwix/CoreData/Classes/Language.swift | 2 -- .../1.8.xcdatamodel/contents | 4 ++-- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Kiwix-iOS/Controller/Library/CloudBooksController.swift b/Kiwix-iOS/Controller/Library/CloudBooksController.swift index ab824c58..6f142861 100644 --- a/Kiwix-iOS/Controller/Library/CloudBooksController.swift +++ b/Kiwix-iOS/Controller/Library/CloudBooksController.swift @@ -156,8 +156,7 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel self.managedObjectContext.performBlock({ let codes = NSLocale.preferredLangCodes Language.fetchAll(self.managedObjectContext).forEach({ (language) in - guard let code = language.code else {return} - language.isDisplayed = codes.contains(code) + language.isDisplayed = codes.contains(language.code) }) self.refreshFetchedResultController() }) diff --git a/Kiwix-iOS/Controller/Library/LanguageFilterController.swift b/Kiwix-iOS/Controller/Library/LanguageFilterController.swift index 53cc7aa9..8b8927b9 100644 --- a/Kiwix-iOS/Controller/Library/LanguageFilterController.swift +++ b/Kiwix-iOS/Controller/Library/LanguageFilterController.swift @@ -112,8 +112,8 @@ class LanguageFilterController: UITableViewController, NSFetchedResultsControlle func sortByCountDesc(languages: [Language]) -> [Language] { return languages.sort { (language0, language1) -> Bool in - guard let count0 = language0.books?.count, - let count1 = language1.books?.count else {return false} + let count0 = language0.books.count + let count1 = language1.books.count guard count0 != count1 else { return alphabeticalAscCompare(language0: language0, language1: language1, byOriginalLocale: Preference.LangFilter.displayInOriginalLocale) } @@ -159,7 +159,7 @@ class LanguageFilterController: UITableViewController, NSFetchedResultsControlle func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath, language: Language) { cell.textLabel?.text = Preference.LangFilter.displayInOriginalLocale ? language.nameInOriginalLocale : language.nameInCurrentLocale - cell.detailTextLabel?.text = language.books?.count.description + cell.detailTextLabel?.text = language.books.count.description } override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 418a4cad..cf6bc8d4 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.42 + 1.8.60 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index 3fd29001..d73c6d88 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.8.1 + 1.8.62 NSExtension NSExtensionMainStoryboard diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index 04992074..a80dd934 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -136,7 +136,6 @@ 97D6813F1D6F712800E5FA99 /* Article+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6813B1D6F712800E5FA99 /* Article+CoreDataProperties.swift */; }; 97D681401D6F712800E5FA99 /* Book+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6813C1D6F712800E5FA99 /* Book+CoreDataProperties.swift */; }; 97D681411D6F712800E5FA99 /* DownloadTask+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6813D1D6F712800E5FA99 /* DownloadTask+CoreDataProperties.swift */; }; - 97D681421D6F712800E5FA99 /* Language+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6813E1D6F712800E5FA99 /* Language+CoreDataProperties.swift */; }; 97D681441D6F713200E5FA99 /* CoreDataExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D681431D6F713200E5FA99 /* CoreDataExtension.swift */; }; 97DB65DA1D4576B600A2CC42 /* BookmarkWidgetCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97DB65D91D4576B600A2CC42 /* BookmarkWidgetCell.swift */; }; 97DF259C1D6F7613001648A3 /* BookOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97DF259B1D6F7612001648A3 /* BookOperation.swift */; }; @@ -147,6 +146,7 @@ 97E850CB1D2DA5B300A9F688 /* About.html in Resources */ = {isa = PBXBuildFile; fileRef = 97E850CA1D2DA5B300A9F688 /* About.html */; }; 97F03CE21D2440470040D26E /* Search.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97F03CE11D2440470040D26E /* Search.storyboard */; }; 97FD5CE71D3D90B7001C74A2 /* getSnippet.js in Resources */ = {isa = PBXBuildFile; fileRef = 97FD5CE61D3D90B7001C74A2 /* getSnippet.js */; }; + 97FDACC41D85A3B300DEDACB /* Language+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6813E1D6F712800E5FA99 /* Language+CoreDataProperties.swift */; }; EB1C0984A03359CD5CDC011C /* Pods_Kiwix_OSX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 198ECFA618CDD6B29CD462A0 /* Pods_Kiwix_OSX.framework */; }; /* End PBXBuildFile section */ @@ -1092,6 +1092,7 @@ isa = PBXNativeTarget; buildConfigurationList = 9779C31F1D4575AE0064CC8E /* Build configuration list for PBXNativeTarget "Bookmarks" */; buildPhases = ( + 97FDACC31D859C3500DEDACB /* ShellScript */, 9779C30F1D4575AD0064CC8E /* Sources */, 9779C3101D4575AD0064CC8E /* Frameworks */, 9779C3111D4575AD0064CC8E /* Resources */, @@ -1110,10 +1111,10 @@ buildConfigurationList = 97A2ABB31C1B810000052E74 /* Build configuration list for PBXNativeTarget "Kiwix-iOS" */; buildPhases = ( CDD21917A84F651D4CEFF569 /* [CP] Check Pods Manifest.lock */, + 97A4D7E21CF8C318006C731E /* ShellScript */, 97A2AB841C1B80FF00052E74 /* Sources */, 97A2AB851C1B80FF00052E74 /* Frameworks */, 97A2AB861C1B80FF00052E74 /* Resources */, - 97A4D7E21CF8C318006C731E /* ShellScript */, 97E609FF1D103DED00EBCB9D /* Embed App Extensions */, 7D32C417880EE3A4FFF4017C /* [CP] Embed Pods Frameworks */, 20E4CC4E024923B9E858CC06 /* [CP] Copy Pods Resources */, @@ -1394,6 +1395,19 @@ shellPath = /bin/sh; shellScript = "#!/bin/bash\nbuildNumber=$(/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" \"$INFOPLIST_FILE\")\nbuildNumber=$(($buildNumber + 1))\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"$INFOPLIST_FILE\""; }; + 97FDACC31D859C3500DEDACB /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "#!/bin/bash\nbuildNumString=$(/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" \"$INFOPLIST_FILE\")\nversionNumber=$(/usr/libexec/PlistBuddy -c \"Print CFBundleShortVersionString\" \"$INFOPLIST_FILE\")\nIFS='.'; arr=($buildNumString)\nlastIndex=$((${#arr[@]} - 1))\nbuildNumber=$((${arr[lastIndex]} + 1))\nbuildNumString=\"${arr[0]}.${arr[1]}.$buildNumber\"\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumString\" \"$INFOPLIST_FILE\""; + }; 99B6C5B82907BC9766F6107C /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -1498,6 +1512,7 @@ 97A1FD391D6F724E00A80EE2 /* pathTools.cpp in Sources */, 970E68B61D37E224001E8514 /* SettingSearchHistoryTBVC.swift in Sources */, 97C005D81D64B99E004352E8 /* LibrarySplitViewController.swift in Sources */, + 97FDACC41D85A3B300DEDACB /* Language+CoreDataProperties.swift in Sources */, 97A7017F1D2C59CA00AAE2D8 /* GetStartedController.swift in Sources */, 97A8AD871D6CF38000584ED1 /* EmptyTableConfigExtension.swift in Sources */, 971A102E1D022AD5007FC62C /* TableViewCells.swift in Sources */, @@ -1515,7 +1530,6 @@ 97D681381D6F711A00E5FA99 /* Book.swift in Sources */, 970E68B21D37E1DD001E8514 /* SettingSearchTuneController.swift in Sources */, 97C005DC1D64BEFE004352E8 /* CloudBooksController.swift in Sources */, - 97D681421D6F712800E5FA99 /* Language+CoreDataProperties.swift in Sources */, 97D681371D6F711A00E5FA99 /* Article.swift in Sources */, 97D681231D6F70AC00E5FA99 /* GlobalQueue.swift in Sources */, 97A1FD3B1D6F724E00A80EE2 /* stringTools.cpp in Sources */, diff --git a/Kiwix/CoreData/Classes/Language+CoreDataProperties.swift b/Kiwix/CoreData/Classes/Language+CoreDataProperties.swift index 47d04782..522be34d 100644 --- a/Kiwix/CoreData/Classes/Language+CoreDataProperties.swift +++ b/Kiwix/CoreData/Classes/Language+CoreDataProperties.swift @@ -14,9 +14,9 @@ import CoreData extension Language { - @NSManaged var code: String? - @NSManaged var isDisplayed: NSNumber? + @NSManaged var code: String + @NSManaged var isDisplayed: Bool @NSManaged var name: String? - @NSManaged var books: NSSet? + @NSManaged var books: Set } diff --git a/Kiwix/CoreData/Classes/Language.swift b/Kiwix/CoreData/Classes/Language.swift index b1fcb201..be6d4035 100644 --- a/Kiwix/CoreData/Classes/Language.swift +++ b/Kiwix/CoreData/Classes/Language.swift @@ -45,12 +45,10 @@ class Language: NSManagedObject { // MARK: - Computed Properties var nameInCurrentLocale: String? { - guard let code = code else {return nil} return NSLocale.currentLocale().displayNameForKey(NSLocaleIdentifier, value: code) } var nameInOriginalLocale: String? { - guard let code = code else {return nil} return NSLocale(localeIdentifier: code).displayNameForKey(NSLocaleIdentifier, value: code) } } diff --git a/Kiwix/CoreData/Kiwix.xcdatamodeld/1.8.xcdatamodel/contents b/Kiwix/CoreData/Kiwix.xcdatamodeld/1.8.xcdatamodel/contents index 4a9af3bd..1b4ee47e 100644 --- a/Kiwix/CoreData/Kiwix.xcdatamodeld/1.8.xcdatamodel/contents +++ b/Kiwix/CoreData/Kiwix.xcdatamodeld/1.8.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -112,7 +112,7 @@ - + \ No newline at end of file