diff --git a/README.md b/README.md index 541b844..2cad066 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ As the app is still in development and there are a lot of small items on this li ### Important - [ ] Update as needed to ensure compatibility with the new web app -- [ ] Fix the core data crash (results occasionally from the "Refresh event data now" button in settings) **--Claimed** +- [ ] Fix the core data crash (results occasionally from the "Refresh event data now" button in settings). @nathanielbscout took a look at this but couldn't reliably reproduce it - it is not fixed. - [ ] Thoroughly test error display in different (re)load scenarios - [ ] Ask server if there are new notifications past a certain date / fetch new notifications after a certain date (would likely require server changes) - [ ] About screen. It is hooked up but has no meaningful content. @@ -75,8 +75,8 @@ As the app is still in development and there are a lot of small items on this li - [ ] Create an app widget (to give directions without being in the app; be cognizant of different map apps) - [ ] Alternate event app text (in place of logo when it is missing, like in the android app) - [ ] Swipe from edge of screen to open menu -- [ ] Improve managed object context usage (the data controller appears to violate Apple documentation's concurrency section by passing contexts between threads) **--Claimed** -- [ ] Make sure prayer partner groups have the same numbers as in the android app **--Claimed** -- [ ] Add some kind of order key to objects received in an array (not a dictionary) and update sorting to use that. **--Claimed** +- [ ] Improve managed object context usage (the data controller appears to violate Apple documentation's concurrency section by passing contexts between threads). @nathanielbscout took a look at this, but found that it only happens in a couple of places. It may cause some trouble, but there are not any clear issues with it. +- [x] Make sure prayer partner groups have the same numbers as in the android app. +- [x] Add some kind of order key to objects received in an array (not a dictionary) and update sorting to use that. - [ ] Start refresh timer when opening the app to go off when it would have gone off, if the timer did not fire when the app was opened. - [ ] Fix white bar above sidebar menu (very noticeable in app switcher) diff --git a/iOSEventApp.xcodeproj/project.pbxproj b/iOSEventApp.xcodeproj/project.pbxproj index 4cce20c..793e933 100644 --- a/iOSEventApp.xcodeproj/project.pbxproj +++ b/iOSEventApp.xcodeproj/project.pbxproj @@ -101,6 +101,7 @@ F1AF66712053292300B8820D /* ContactTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactTableViewCell.swift; sourceTree = ""; }; F1AF66732053433B00B8820D /* NotificationTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationTableViewCell.swift; sourceTree = ""; }; F1DB720A20A6655C00B30C54 /* iOSEventAppV2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = iOSEventAppV2.xcdatamodel; sourceTree = ""; }; + F1EE2DC422453D88006E9A1A /* iOSEventAppV3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = iOSEventAppV3.xcdatamodel; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -718,10 +719,11 @@ F149D6CE204DCE2F000DA81A /* iOSEventApp.xcdatamodeld */ = { isa = XCVersionGroup; children = ( + F1EE2DC422453D88006E9A1A /* iOSEventAppV3.xcdatamodel */, F1DB720A20A6655C00B30C54 /* iOSEventAppV2.xcdatamodel */, F149D6CF204DCE2F000DA81A /* iOSEventApp.xcdatamodel */, ); - currentVersion = F1DB720A20A6655C00B30C54 /* iOSEventAppV2.xcdatamodel */; + currentVersion = F1EE2DC422453D88006E9A1A /* iOSEventAppV3.xcdatamodel */; path = iOSEventApp.xcdatamodeld; sourceTree = ""; versionGroupType = wrapper.xcdatamodel; diff --git a/iOSEventApp/MainContainerViewController.swift b/iOSEventApp/MainContainerViewController.swift index ae9e80a..6108ded 100644 --- a/iOSEventApp/MainContainerViewController.swift +++ b/iOSEventApp/MainContainerViewController.swift @@ -17,7 +17,11 @@ protocol TakesArrayData: AnyObject { var dataArray: [Any]? { get set } } -/// A workaround to allow sorting of data without having to do a separate if else for every data type. +/** + A workaround to allow sorting of data without having to do a separate if else for every data type. + + It is important to sort for consistency across devices - although sometimes the order needs to be kept the same as in the JSON (e.g. prayer partners), which can be handled by passing the indices as strings. + */ protocol IsComparable { var compareString: String? { get } } @@ -168,7 +172,8 @@ class MainContainerViewController: UIViewController { } if let takesArrayData = vc as? TakesArrayData { - if let sortable = data as? [IsComparable] { // All objects in the array are the same type + // Sort the data if possible - it is simpler to sort here and not in each individual sidebar view controller. + if let sortable = data as? [IsComparable] { takesArrayData.dataArray = sortable.sorted(by: { (obj1, obj2) -> Bool in guard let str1 = obj1.compareString, let str2 = obj2.compareString else { return false diff --git a/iOSEventApp/Model/DataController.swift b/iOSEventApp/Model/DataController.swift index 4c7eaad..72f7b95 100644 --- a/iOSEventApp/Model/DataController.swift +++ b/iOSEventApp/Model/DataController.swift @@ -69,7 +69,7 @@ struct MalformedDataInformation: CustomStringConvertible { DataController also starts the refresh timer in the refreshController, which it keeps a static reference to. The refresh timer triggers a reload of notifications. - Passing a context around different threads is against recommended practice. It will remain as is until changed. + The context should not be carelessly accessed from a thread different from the one it was created on. The only time a context is potentially passed between threads in this class is when a data task is performed - and it may be improperly handled in `loadNotificationsFromURL` or methods that call it, but since there are no clear issues right now it is being left alone. */ class DataController: NSObject { @@ -150,6 +150,8 @@ class DataController: NSObject { return } + // This is in a performBackgroundTask block. + // I still don't think the context should *really* be passed like this, but there are no apparent issues with this at the moment. self.loadNotificationsFromURL(context: context, url: URL(string: notificationsURLString)!) { (success, nErrors, newNotifications) in if let additionalErrors = nErrors { if case .unableToSave(_)? = additionalErrors.first { @@ -391,10 +393,11 @@ extension DataController { var sidebarKVPairs = [String: String]() let groupDicts = partnerGroups as! [[String: Any]] - for obj in groupDicts { + // The prayer partners come in an array, and so the order should be preserved. + for (index, obj) in groupDicts.enumerated() { if let partnerNames = obj["students"] { if partnerNames is String { - groupstoCreate.append(["students": partnerNames]) + groupstoCreate.append(["students": partnerNames, "order": Int16(index)]) } else { errors.append(.partiallyMalformed(MalformedDataInformation(objectName: "PrayerPartnerGroup", propertyName: "students", missingProperty: nil))) @@ -638,7 +641,7 @@ extension DataController { sidebarNum += 1 let pageIdentifier = key - // Ideally this wouldn't be hardcoded for an index of 0 + // The event data has the sidebar info at the first index of each page array guard let sidebarName = value[0][sidebarNameKey] as? String else { errors.append(.partiallyMalformed(MalformedDataInformation(objectName: "Information Page \(pageNum)", propertyName: pageIdentifier, missingProperty: sidebarNameKey))) continue diff --git a/iOSEventApp/Model/iOSEventApp.xcdatamodeld/.xccurrentversion b/iOSEventApp/Model/iOSEventApp.xcdatamodeld/.xccurrentversion index 501bbc9..e3afa60 100644 --- a/iOSEventApp/Model/iOSEventApp.xcdatamodeld/.xccurrentversion +++ b/iOSEventApp/Model/iOSEventApp.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - iOSEventAppV2.xcdatamodel + iOSEventAppV3.xcdatamodel diff --git a/iOSEventApp/Model/iOSEventApp.xcdatamodeld/iOSEventAppV3.xcdatamodel/contents b/iOSEventApp/Model/iOSEventApp.xcdatamodeld/iOSEventAppV3.xcdatamodel/contents new file mode 100644 index 0000000..d502301 --- /dev/null +++ b/iOSEventApp/Model/iOSEventApp.xcdatamodeld/iOSEventAppV3.xcdatamodel/contents @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iOSEventApp/SidebarItemViewControllers/PrayerPartnersViewController.swift b/iOSEventApp/SidebarItemViewControllers/PrayerPartnersViewController.swift index d22fbdc..e705908 100644 --- a/iOSEventApp/SidebarItemViewControllers/PrayerPartnersViewController.swift +++ b/iOSEventApp/SidebarItemViewControllers/PrayerPartnersViewController.swift @@ -10,7 +10,7 @@ import UIKit extension PrayerPartnerGroup: IsComparable { var compareString: String? { - return students + return String(order) } }