Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repository pattern #24

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
excluded:
- Pods
- ../MuslimData/Classes/Prayer Times/Prayer.swift
- ../MuslimData/Classes/Models/PrayerTimes/Prayer.swift
included:
- ../MuslimData
identifier_name:
Expand Down
26 changes: 4 additions & 22 deletions Example/MuslimData.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
2D1D63A32B9CCF2100DBC74B /* MIGRATION_GUIDE.md in Resources */ = {isa = PBXBuildFile; fileRef = 2D1D63A22B9CCF2100DBC74B /* MIGRATION_GUIDE.md */; };
2D27AC4B2188E621004722BD /* LocationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D27AC4A2188E621004722BD /* LocationViewController.swift */; };
2D4558BA21694A5200A08DAF /* LocationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4558B921694A5200A08DAF /* LocationTests.swift */; };
2D4EC4D42B835D7C00F08DCB /* IQCityMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4EC4D32B835D7C00F08DCB /* IQCityMapperTests.swift */; };
2D4EC4D72B83637A00F08DCB /* IRCityMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4EC4D62B83637A00F08DCB /* IRCityMapperTests.swift */; };
2D4EC4D92B83639E00F08DCB /* KWCityMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4EC4D82B83639E00F08DCB /* KWCityMapperTests.swift */; };
2D6B21C421708D600054F8C0 /* NamesTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D6B21C321708D600054F8C0 /* NamesTest.swift */; };
2D9FC355217278E0003EF074 /* AzkarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D9FC354217278E0003EF074 /* AzkarTests.swift */; };
2DBD7E7B218E01AF00B6595B /* AzkarChaptersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DBD7E7A218E01AF00B6595B /* AzkarChaptersViewController.swift */; };
Expand Down Expand Up @@ -45,9 +42,6 @@
2D1D63A22B9CCF2100DBC74B /* MIGRATION_GUIDE.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = MIGRATION_GUIDE.md; path = ../MIGRATION_GUIDE.md; sourceTree = "<group>"; };
2D27AC4A2188E621004722BD /* LocationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationViewController.swift; sourceTree = "<group>"; };
2D4558B921694A5200A08DAF /* LocationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationTests.swift; sourceTree = "<group>"; };
2D4EC4D32B835D7C00F08DCB /* IQCityMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IQCityMapperTests.swift; sourceTree = "<group>"; };
2D4EC4D62B83637A00F08DCB /* IRCityMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IRCityMapperTests.swift; sourceTree = "<group>"; };
2D4EC4D82B83639E00F08DCB /* KWCityMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KWCityMapperTests.swift; sourceTree = "<group>"; };
2D6B21C321708D600054F8C0 /* NamesTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NamesTest.swift; sourceTree = "<group>"; };
2D9FC354217278E0003EF074 /* AzkarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AzkarTests.swift; sourceTree = "<group>"; };
2DBD7E7A218E01AF00B6595B /* AzkarChaptersViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AzkarChaptersViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -104,16 +98,6 @@
name = Pods;
sourceTree = "<group>";
};
2D4EC4D52B83634200F08DCB /* CityMapperTests */ = {
isa = PBXGroup;
children = (
2D4EC4D32B835D7C00F08DCB /* IQCityMapperTests.swift */,
2D4EC4D62B83637A00F08DCB /* IRCityMapperTests.swift */,
2D4EC4D82B83639E00F08DCB /* KWCityMapperTests.swift */,
);
path = CityMapperTests;
sourceTree = "<group>";
};
2DBD7E7C218E01BF00B6595B /* Azkars */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -214,7 +198,6 @@
607FACE81AFB9204008FA782 /* Tests */ = {
isa = PBXGroup;
children = (
2D4EC4D52B83634200F08DCB /* CityMapperTests */,
2D9FC354217278E0003EF074 /* AzkarTests.swift */,
2D6B21C321708D600054F8C0 /* NamesTest.swift */,
2D110EDD216BE7FB002035FA /* PrayerTests.swift */,
Expand Down Expand Up @@ -466,12 +449,9 @@
buildActionMask = 2147483647;
files = (
2D110EDE216BE7FB002035FA /* PrayerTests.swift in Sources */,
2D4EC4D92B83639E00F08DCB /* KWCityMapperTests.swift in Sources */,
2D6B21C421708D600054F8C0 /* NamesTest.swift in Sources */,
2D4558BA21694A5200A08DAF /* LocationTests.swift in Sources */,
2D9FC355217278E0003EF074 /* AzkarTests.swift in Sources */,
2D4EC4D72B83637A00F08DCB /* IRCityMapperTests.swift in Sources */,
2D4EC4D42B835D7C00F08DCB /* IQCityMapperTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -554,11 +534,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -604,11 +585,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
6 changes: 2 additions & 4 deletions Example/MuslimData/AzkarChaptersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ class AzkarChaptersViewController: UIViewController {
chaptersTable.dataSource = self

// Get azkar chapters from MuslimData library.
Azkars.azkarChapters(language: .en) { chapters, error in
guard error == nil else {
return
}
Task.init {
let chapters = try! await MuslimRepository().getAzkarChapters(language: .en)
self.chapters = chapters!
self.chaptersTable.reloadData()
}
Expand Down
8 changes: 3 additions & 5 deletions Example/MuslimData/AzkarDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ class AzkarDetailViewController: UIViewController {
azkarTable.tableFooterView = UIView()

// Get azkar items from MuslimData library.
Azkars.azkarItems(language: .en, chapterId: azkarChapter!.id) { azkars, error in
guard error == nil else {
return
}
self.azkars = azkars!
Task.init {
let items = try! await MuslimRepository().getAzkarItems(language: .en, chapterId: azkarChapter!.id)
self.azkars = items!
self.azkarTable.reloadData()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Example/MuslimData/Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension Location {
/// - Returns: Location object.
static func loadSavedLocation() -> Location {
let defaults = UserDefaults.standard
let id = defaults.integer(forKey: "id")
let id = defaults.object(forKey: "id") as? Int ?? 77359
let name = defaults.string(forKey: "name") ?? "Erbil"
var latitude = defaults.double(forKey: "latitude")
latitude = latitude == 0.0 ? 36.188204 : latitude
Expand Down
6 changes: 2 additions & 4 deletions Example/MuslimData/LocationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ extension LocationViewController: UISearchBarDelegate {
locations.removeAll()
return
}
LocationHelper.shared.citySearch(searchBar.text!) { locations, error in
guard error == nil else {
return
}
Task.init {
let locations = try! await MuslimRepository().searchLocation(locationName: searchBar.text!)
if let locations = locations {
self.locations = locations
}
Expand Down
7 changes: 2 additions & 5 deletions Example/MuslimData/NamesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ class NamesViewController: UIViewController {

namesTable.dataSource = self

// Get names of allah from MuslimData.
Names.names(language: .en) { names, error in
guard error == nil else {
return
}
Task.init {
let names = try! await MuslimRepository().getNamesOfAllah(language: .en)
self.names = names!
self.namesTable.reloadData()
}
Expand Down
18 changes: 8 additions & 10 deletions Example/MuslimData/PrayersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,22 @@ class PrayersViewController: UIViewController {
super.viewWillAppear(animated)

// Get prayer times
getPrayers()
Task.init {
try! await getPrayers()
}
}

// MARK: - Helper Methods

/// Get prayer times from the MuslimData library
func getPrayers() {
func getPrayers() async throws {
let offsets = [Double](repeating: 0, count: 6)
let location = Location.loadSavedLocation()
let attributes = PrayerAttribute(method: .makkah, asrMethod: .shafii, adjustAngle: .angleBased, offsets: offsets)
PrayerTime.getPrayerTimes(location: location, date: Date(),
attributes: attributes) { prayerTime, error in
guard error == nil else {
return
}
self.prayerTimes = prayerTime!.formatPrayers(.time12)
self.prayerTable.reloadData()
}

let prayer = try await MuslimRepository().getPrayerTimes(location: location, date: Date(), attributes: attributes)
prayerTimes = prayer!.formatPrayers(.time12)
prayerTable.reloadData()

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd MMM yyyy"
Expand Down
Loading
Loading