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

Refactor database tables #23

Merged
merged 13 commits into from
Mar 20, 2024
8 changes: 6 additions & 2 deletions Example/MuslimData.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
2D110EDE216BE7FB002035FA /* PrayerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D110EDD216BE7FB002035FA /* PrayerTests.swift */; };
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 */; };
Expand Down Expand Up @@ -41,6 +42,7 @@
/* Begin PBXFileReference section */
1FA7CF45010583A8DE450B74 /* Pods-MuslimData_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MuslimData_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MuslimData_Example/Pods-MuslimData_Example.debug.xcconfig"; sourceTree = "<group>"; };
2D110EDD216BE7FB002035FA /* PrayerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrayerTests.swift; sourceTree = "<group>"; };
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>"; };
Expand Down Expand Up @@ -235,6 +237,7 @@
children = (
CBF44BC9BD957BA32BBAB0D7 /* MuslimData.podspec */,
E0705505FB7482A035EE85A3 /* README.md */,
2D1D63A22B9CCF2100DBC74B /* MIGRATION_GUIDE.md */,
C7F9702CA1CFE6102812811C /* LICENSE */,
);
name = "Podspec Metadata";
Expand Down Expand Up @@ -330,6 +333,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2D1D63A32B9CCF2100DBC74B /* MIGRATION_GUIDE.md in Resources */,
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
Expand Down Expand Up @@ -363,7 +367,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
2DABCDEA216296CC008F4B9B /* SwiftFormat */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -382,7 +386,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftformat >/dev/null; then\n swiftformat ../MuslimData\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n";
shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftformat > /dev/null; then\n swiftformat .\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n";
};
379ECBACD51077EED9BCFABC /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
7 changes: 1 addition & 6 deletions Example/MuslimData/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
true
}

func applicationWillResignActive(_ application: UIApplication) {
Expand All @@ -40,7 +38,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

9 changes: 4 additions & 5 deletions Example/MuslimData/AzkarChaptersViewController.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
//
// AzkarsViewController.swift
// AzkarChaptersViewController.swift
// MuslimData_Example
//
// Created by Kosrat D. Ahmad on 11/3/18.
// Copyright © 2018 CocoaPods. All rights reserved.
//

import UIKit
import MuslimData
import UIKit

class AzkarChaptersViewController: UIViewController {

// MARK: - Outlets

@IBOutlet weak var chaptersTable: UITableView!
@IBOutlet var chaptersTable: UITableView!

// MARK: - Properties

Expand Down Expand Up @@ -53,7 +52,7 @@ extension AzkarChaptersViewController: UITableViewDelegate {

extension AzkarChaptersViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return chapters.count
chapters.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down
6 changes: 3 additions & 3 deletions Example/MuslimData/AzkarDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
// Copyright © 2018 CocoaPods. All rights reserved.
//

import UIKit
import MuslimData
import UIKit

class AzkarDetailViewController: UIViewController {
// MARK: - Outlets

@IBOutlet weak var azkarTable: UITableView!
@IBOutlet var azkarTable: UITableView!

// MARK: - Properties

Expand Down Expand Up @@ -44,7 +44,7 @@ class AzkarDetailViewController: UIViewController {

extension AzkarDetailViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return azkars.count
azkars.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down
2 changes: 2 additions & 0 deletions Example/MuslimData/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
</dict>
</plist>
13 changes: 9 additions & 4 deletions Example/MuslimData/Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,34 @@ extension Location {
/// Save location in the User Defaults.
func saveLocation() {
let defaults = UserDefaults.standard
defaults.set(id, forKey: "id")
defaults.set(name, forKey: "name")
defaults.set(latitude, forKey: "latitude")
defaults.set(longitude, forKey: "longitude")
defaults.set(cityName, forKey: "city")
defaults.set(countryCode, forKey: "countryCode")
defaults.set(countryName, forKey: "countryName")
defaults.set(hasFixedPrayerTime, forKey: "hasFixedPrayerTime")
defaults.set(prayerDependentId, forKey: "prayerDependentId")
}

/// Load saved location from User Defaults.
///
/// - Returns: Location object.
static func loadSavedLocation() -> Location {
let defaults = UserDefaults.standard
let id = defaults.integer(forKey: "id")
let name = defaults.string(forKey: "name") ?? "Erbil"
var latitude = defaults.double(forKey: "latitude")
latitude = latitude == 0.0 ? 36.188204 : latitude
var longitude = defaults.double(forKey: "longitude")
longitude = longitude == 0.0 ? 43.966606 : longitude
let cityName = defaults.string(forKey: "city") ?? "Erbil"
let countryCode = defaults.string(forKey: "countryCode") ?? "IQ"
let countryName = defaults.string(forKey: "countryName") ?? "Iraq"
let hasFixedPrayerTime = (defaults.object(forKey: "hasFixedPrayerTime") as? Bool) ?? true
let prayerDependentId = defaults.object(forKey: "prayerDependentId") as? Int

return Location(latitude: latitude, longitude: longitude, cityName: cityName, countryCode: countryCode,
countryName: countryName, hasFixedPrayerTime: hasFixedPrayerTime)
return Location(id: id, name: name, latitude: latitude, longitude: longitude,
countryCode: countryCode, countryName: countryName, hasFixedPrayerTime: hasFixedPrayerTime,
prayerDependentId: prayerDependentId)
}
}
22 changes: 12 additions & 10 deletions Example/MuslimData/LocationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
// Copyright © 2018 CocoaPods. All rights reserved.
//

import UIKit
import MuslimData
import UIKit

class LocationViewController: UIViewController {
// MARK: - Outlets

@IBOutlet weak var locationTitle: UILabel!
@IBOutlet weak var locationTable: UITableView!
@IBOutlet var locationTitle: UILabel!
@IBOutlet var locationTable: UITableView!

var locations: [Location] = [] {
didSet{
didSet {
locationTable.reloadData()
}
}
Expand Down Expand Up @@ -51,7 +51,7 @@ class LocationViewController: UIViewController {
/// Display selected location on the screen.
func displayLocation() {
let location = Location.loadSavedLocation()
locationTitle.text = "\(location.cityName), \(location.countryName)"
locationTitle.text = "\(location.name), \(location.countryName)"
}

/// Dismiss and return to the parent screen.
Expand All @@ -63,6 +63,7 @@ class LocationViewController: UIViewController {
}

// MARK: - UISearchBarDelegate

extension LocationViewController: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if searchText == "" {
Expand All @@ -75,35 +76,36 @@ extension LocationViewController: UISearchBarDelegate {
}
if let locations = locations {
self.locations = locations

}
}
}
}

// MARK: - UITableViewDelegate

extension LocationViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let location = locations[indexPath.row]

location.saveLocation()
self.displayLocation()
displayLocation()
if #available(iOS 11.0, *) {
navigationItem.searchController?.isActive = false
}
}
}

// MARK: - UITableViewDataSource

extension LocationViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return locations.count
locations.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath)
let location = locations[indexPath.row]
cell.textLabel?.text = location.cityName
cell.textLabel?.text = location.name
cell.detailTextLabel?.text = location.countryName

return cell
Expand Down
9 changes: 4 additions & 5 deletions Example/MuslimData/NamesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
// Copyright © 2018 CocoaPods. All rights reserved.
//

import UIKit
import MuslimData
import UIKit

class NamesViewController: UIViewController {

// MARK: - Outlets

@IBOutlet weak var namesTable: UITableView!
@IBOutlet var namesTable: UITableView!

// MARK: - Properties

Expand All @@ -39,9 +38,9 @@ class NamesViewController: UIViewController {

// MARK: - UITableViewDataSource

extension NamesViewController: UITableViewDataSource {
extension NamesViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
names.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down
14 changes: 7 additions & 7 deletions Example/MuslimData/PrayersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// Copyright © 2018 CocoaPods. All rights reserved.
//

import UIKit
import MuslimData
import UIKit

class PrayersViewController: UIViewController {
// MARK: - Outlets

@IBOutlet weak var locationDetail: UILabel!
@IBOutlet weak var prayerTable: UITableView!
@IBOutlet var locationDetail: UILabel!
@IBOutlet var prayerTable: UITableView!

// MARK: - Properties

Expand All @@ -26,7 +26,7 @@ class PrayersViewController: UIViewController {
super.viewDidLoad()

prayerTable.dataSource = self
prayerTable.tableFooterView = UIView()
prayerTable.tableFooterView = UIView()
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -44,7 +44,7 @@ class PrayersViewController: UIViewController {
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
attributes: attributes) { prayerTime, error in
guard error == nil else {
return
}
Expand All @@ -56,15 +56,15 @@ class PrayersViewController: UIViewController {
dateFormatter.dateFormat = "dd MMM yyyy"
let stringDate = dateFormatter.string(from: Date())

locationDetail.text = "\(location.cityName), \(location.countryName)\n\(stringDate)"
locationDetail.text = "\(location.name), \(location.countryName)\n\(stringDate)"
}
}

// MARK: - UITableViewDataSource

extension PrayersViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return prayerTimes.count
prayerTimes.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down
Loading
Loading