Compare commits

...

4 Commits

Author SHA1 Message Date
1de87263ba [Improvement] Small, tiny things (#14)
This PR contains the work on implementing some public interfaces that were forgotten during the development of this app and, of course, improves the text of the README file a bit more.

To give further details about the work done:
- [x] implemented the `Service` protocol in the `Persistence` library and conformed the `PersistenceService` service to it;
- [x] implemented the `Service` protocol in the `Remote` library and conformed the `RemoteService` service to it;
- [x] implemented the `Application` protocol in the `Core` library and conformed the `UIApplication` class to it;
- [x] improved the dependency keys used by the `DependencyService` service to use these protocols instead;
- [x] tweaked the text of the README file.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: rock-n-code/deep-linking-assignment#14
2023-04-13 13:34:06 +00:00
842c3e1a6c [Setup] Wrapping up (#13)
This PR contains the work on wrapping the development of this app, at least for the time being.

To give further details on the work done:
- [x] removed the `Shared` package from the project as it was not used;
- [x] added some missing Xcode target schemes;
- [x] added a design document and a demo video;
- [x] written a README document;

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: rock-n-code/deep-linking-assignment#13
2023-04-13 09:25:45 +00:00
57f4b3c237 [Feature] Open Wikipedia app (#12)
This PR contains the work done to open the *Places* view of the **Wikipedia** app with the screen centered on the coordinates from a selected location in the `LocationsListViewController` view controller.

To give further details about the work done:
- [x] implemented the `wikipediaPlacesURL` property in the `Location+URLs` extension;
- [x] improved the `LocationsListCoordination` protocol and the `LocationsListCoordinator` coordinator to support the opening of the Wikipedia app;
- [x] improved the `LocationsListViewModeling` protocol and the `LocationsListViewModel` view model  to support the opening of the Wikipedia app;
- [x] implemented the "tableView(_: didSelectAt: )" function in the `LocationsListViewController` view controller;
- [x] added the "wikipedia" to the Queried URL schemes in the Info.plist file to support querying to the Wikipedia app;
- [x] improved the naming of some properties and functions in the `LocationsAddCoordination`, `LocationsListCoordination`, and `LocationsListViewModeling` protocols.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: rock-n-code/deep-linking-assignment#12
2023-04-12 23:07:42 +00:00
8ae955008e [Feature] Location add (#11)
This PR contains the work done to add a location at a time and updates the locations in the list of locations screen right after.

To give further details about the work done:
- [x] implemented the `LocationProvider` provider in the **Persistence** library;
- [x] implemented the `SaveLocalLocationUseCase` use case;
- [x] defined the properties and functions of the `LocationsAddViewModeling` protocol to support the clean, updating and saving of locations;
- [x] implemented the `LocationsAddViewModel` view model;
- [x] implemented the `LocationsAddViewController` view controller;
- [x] implemented the dismissal of the `LocationsAddCoordinator` coordinator.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: rock-n-code/deep-linking-assignment#11
2023-04-12 21:25:08 +00:00
38 changed files with 1147 additions and 131 deletions

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "APICoreTests"
BuildableName = "APICoreTests"
BlueprintName = "APICoreTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CoreTests"
BuildableName = "CoreTests"
BlueprintName = "CoreTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DependencyTests"
BuildableName = "DependencyTests"
BlueprintName = "DependencyTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Libraries"
BuildableName = "Libraries"
BlueprintName = "Libraries"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Libraries"
BuildableName = "Libraries"
BlueprintName = "Libraries"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PersistenceTests"
BuildableName = "PersistenceTests"
BlueprintName = "PersistenceTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "RemoteTests"
BuildableName = "RemoteTests"
BlueprintName = "RemoteTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,23 @@
//
// Application.swift
// Core
//
// Created by Javier Cicchelli on 13/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Foundation
import UIKit
public protocol Application {
// MARK: Functions
func canOpenURL(_ url: URL) -> Bool
func open(
_ url: URL,
options: [UIApplication.OpenExternalURLOptionsKey : Any],
completionHandler completion: ((Bool) -> Void)?
)
}

View File

@ -0,0 +1,36 @@
//
// Service.swift
// Persistence
//
// Created by Javier Cicchelli on 13/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import CoreData
public protocol Service {
// MARK: Properties
/// The main managed object context.
var viewContext: NSManagedObjectContext { get }
// MARK: Functions
/// Create a private queue context.
/// - Returns: A concurrent `NSManagedObjectContext` context instance ready to use.
func makeTaskContext() -> NSManagedObjectContext
/// Create a child context of the view context.
/// - Returns: A generated child `NSManagedObjectContext` context instance ready to use.
func makeChildContext() -> NSManagedObjectContext
/// Save a given context,
/// - Parameter context: A `NSManagedObjectContext` context instance to save.
func save(context: NSManagedObjectContext)
/// Save a given child context as well as its respective parent context.
/// - Parameter context: A child `NSManagedObjectContext` context instance to save.
func save(childContext context: NSManagedObjectContext)
}

View File

@ -0,0 +1,149 @@
//
// LocationProvider.swift
// Persistence
//
// Created by Javier Cicchelli on 12/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Combine
import CoreData
public class LocationProvider: NSObject {
// MARK: Properties
private let fetchedResultsController: NSFetchedResultsController<Location>
/// The publisher that emits the changes detected to the Location entities in a given object context.
public let didChangePublisher = PassthroughSubject<[Change], Never>()
private var inProgressChanges: [Change] = []
/// The number of sections in the data.
public var numberOfSections: Int { fetchedResultsController.sections?.count ?? 0 }
// MARK: Initialisers
/// Initialise this provider with the managed object context that would be used.
/// - Parameter managedContext: A `NSManagedObjectContext` object context instance that will be used to provide entities.
public init(managedContext: NSManagedObjectContext) {
self.fetchedResultsController = .init(
fetchRequest: .allLocations(),
managedObjectContext: managedContext,
sectionNameKeyPath: nil,
cacheName: nil
)
super.init()
self.fetchedResultsController.delegate = self
}
// MARK: Functions
/// Perform the fetching.
public func fetch() throws {
try fetchedResultsController.performFetch()
}
/// Retrieve the number of locations inside a given section number.
/// - Parameter section: The section number to inquiry about.
/// - Returns: A number of locations inside the given section number.
public func numberOfLocationsInSection(_ section: Int) -> Int {
guard
let sections = fetchedResultsController.sections,
sections.endIndex > section
else {
return 0
}
return sections[section].numberOfObjects
}
/// Retrieve a location entity out of a given index path.
/// - Parameter indexPath: The index path to which retrieve a location entity.
/// - Returns: A `Location` entity positioned in the given index path.
public func location(at indexPath: IndexPath) -> Location {
return fetchedResultsController.object(at: indexPath)
}
}
// MARK: - NSFetchedResultsControllerDelegate
extension LocationProvider: NSFetchedResultsControllerDelegate {
// MARK: Functions
public func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
inProgressChanges.removeAll()
}
public func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
didChangePublisher.send(inProgressChanges)
}
public func controller(
_ controller: NSFetchedResultsController<NSFetchRequestResult>,
didChange sectionInfo: NSFetchedResultsSectionInfo,
atSectionIndex sectionIndex: Int,
for type: NSFetchedResultsChangeType
) {
if type == .insert {
inProgressChanges.append(.section(.inserted(sectionIndex)))
} else if type == .delete {
inProgressChanges.append(.section(.deleted(sectionIndex)))
}
}
public func controller(
_ controller: NSFetchedResultsController<NSFetchRequestResult>,
didChange anObject: Any,
at indexPath: IndexPath?,
for type: NSFetchedResultsChangeType,
newIndexPath: IndexPath?
) {
switch type {
case .insert:
guard let newIndexPath else { return }
inProgressChanges.append(.object(.inserted(at: newIndexPath)))
case .delete:
guard let indexPath else { return }
inProgressChanges.append(.object(.deleted(from: indexPath)))
case .move:
guard let indexPath, let newIndexPath else { return }
inProgressChanges.append(.object(.moved(from: indexPath, to: newIndexPath)))
case .update:
guard let indexPath else { return }
inProgressChanges.append(.object(.updated(at: indexPath)))
default:
break
}
}
}
// MARK: - Enumerations
public enum Change: Hashable {
public enum SectionUpdate: Hashable {
case inserted(Int)
case deleted(Int)
}
public enum ObjectUpdate: Hashable {
case inserted(at: IndexPath)
case deleted(from: IndexPath)
case updated(at: IndexPath)
case moved(from: IndexPath, to: IndexPath)
}
case section(SectionUpdate)
case object(ObjectUpdate)
}

View File

@ -26,7 +26,7 @@ public struct PersistenceService {
else {
fatalError("Could not load the model from the library.")
}
container = NSPersistentContainer(
name: .Model.name,
managedObjectModel: managedObjectModel
@ -35,10 +35,18 @@ public struct PersistenceService {
setContainer(inMemory)
}
// MARK: Functions
}
// MARK: - Service
extension PersistenceService: Service {
/// Create a private queue context.
/// - Returns: A concurrent `NSManagedObjectContext` context instance ready to use.
// MARK: Properties
public var viewContext: NSManagedObjectContext { container.viewContext }
// MARK: Functions
public func makeTaskContext() -> NSManagedObjectContext {
let taskContext = container.newBackgroundContext()
@ -48,8 +56,6 @@ public struct PersistenceService {
return taskContext
}
/// Create a child context of the view context.
/// - Returns: A generated child `NSManagedObjectContext` context instance ready to use.
public func makeChildContext() -> NSManagedObjectContext {
let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
@ -60,8 +66,6 @@ public struct PersistenceService {
return context
}
/// Save a given context,
/// - Parameter context: A `NSManagedObjectContext` context instance to save.
public func save(context: NSManagedObjectContext) {
guard context.hasChanges else {
return
@ -75,8 +79,6 @@ public struct PersistenceService {
}
}
/// Save a given child context as well as its respective parent context.
/// - Parameter context: A child `NSManagedObjectContext` context instance to save.
public func save(childContext context: NSManagedObjectContext) {
guard context.hasChanges else {
return
@ -100,7 +102,7 @@ public struct PersistenceService {
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
// MARK: - Helpers

View File

@ -16,7 +16,7 @@ public struct Location: Equatable {
// MARK: Initialisers
public init(
init(
name: String? = nil,
latitude: Float,
longitude: Float

View File

@ -0,0 +1,19 @@
//
// Service.swift
// Remote
//
// Created by Javier Cicchelli on 13/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Foundation
public protocol Service {
// MARK: Functions
/// Retrieve a set of locations.
/// - Returns: The set of locations represented as a `Location` instances.
func getLocations() async throws -> [Location]
}

View File

@ -21,6 +21,12 @@ public struct RemoteService {
self.client = RemoteClient(configuration: configuration)
}
}
// MARK: - Service
extension RemoteService: Service {
// MARK: Functions
public func getLocations() async throws -> [Location] {
@ -29,7 +35,7 @@ public struct RemoteService {
for: Locations.self
).locations
}
}
// MARK: - Models

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wikipedia</string>
</array>
</dict>
</plist>

View File

@ -38,4 +38,12 @@ class LocationsAddCoordinator: Coordinator {
// MARK: - LocationsAddCoordination
extension LocationsAddCoordinator: LocationsAddCoordination {}
extension LocationsAddCoordinator: LocationsAddCoordination {
// MARK: Functions
func closeLocationsAddScreen() {
router.dismiss(animated: true)
}
}

View File

@ -7,10 +7,15 @@
//
import Core
import Dependency
import UIKit
class LocationsListCoordinator: Coordinator {
// MARK: Dependencies
@Dependency(\.app) private var app
// MARK: Properties
var children: [Coordinator] = []
@ -48,7 +53,7 @@ extension LocationsListCoordinator: LocationsListCoordination {
// MARK: Functions
func openAddLocation() {
func openLocationsAddScreen() {
guard let viewController else {
return
}
@ -61,4 +66,12 @@ extension LocationsListCoordinator: LocationsListCoordination {
)
}
func openWikipediaApp(with url: URL) {
guard app.canOpenURL(url) else {
return
}
app.open(url, options: [:], completionHandler: nil)
}
}

View File

@ -6,19 +6,26 @@
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Core
import Dependency
import Persistence
import Remote
import UIKit
// MARK: - DependencyService+Keys
extension DependencyService {
var persistence: PersistenceService {
var app: Core.Application {
get { Self[ApplicationKey.self] }
set { Self[ApplicationKey.self] = newValue }
}
var persistence: Persistence.Service {
get { Self[PersistenceKey.self] }
set { Self[PersistenceKey.self] = newValue }
}
var remote: RemoteService {
var remote: Remote.Service {
get { Self[RemoteKey.self] }
set { Self[RemoteKey.self] = newValue }
}
@ -26,10 +33,14 @@ extension DependencyService {
// MARK: - Dependency keys
struct ApplicationKey: DependencyKey {
static var currentValue: Core.Application = UIApplication.shared
}
struct PersistenceKey: DependencyKey {
static var currentValue: PersistenceService = .shared
static var currentValue: Persistence.Service = PersistenceService.shared
}
struct RemoteKey: DependencyKey {
static var currentValue: RemoteService = .init()
static var currentValue: Remote.Service = RemoteService()
}

View File

@ -0,0 +1,46 @@
//
// Location+URLs.swift
// Locations
//
// Created by Javier Cicchelli on 13/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Foundation
import Persistence
extension Location {
var wikipediaPlacesURL: URL? {
var urlComponents = URLComponents()
urlComponents.scheme = .Scheme.wikipedia
urlComponents.host = .Host.places
urlComponents.queryItems = [
.init(
name: .Query.key,
value: .init(format: .Query.value, latitude, longitude)
)
]
return urlComponents.url
}
}
// MARK: - String+Constants
private extension String {
enum Scheme {
static let wikipedia = "wikipedia"
}
enum Host {
static let places = "places"
}
enum Query {
static let key = "coordinates"
static let value = "%f,%f"
}
}

View File

@ -0,0 +1,12 @@
//
// UIApplication+Conformances.swift
// Locations
//
// Created by Javier Cicchelli on 13/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Core
import UIKit
extension UIApplication: Application {}

View File

@ -6,4 +6,10 @@
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
protocol LocationsAddCoordination: AnyObject {}
protocol LocationsAddCoordination: AnyObject {
// MARK: Functions
func closeLocationsAddScreen()
}

View File

@ -6,10 +6,13 @@
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Foundation
protocol LocationsListCoordination: AnyObject {
// MARK: Functions
func openAddLocation()
func openLocationsAddScreen()
func openWikipediaApp(with url: URL)
}

View File

@ -6,10 +6,20 @@
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Combine
protocol LocationsAddViewModeling: AnyObject {
// MARK: Properties
var coordinator: LocationsAddCoordination? { get set }
var locationExistsPublisher: Published<Bool>.Publisher { get }
// MARK: Functions
func cleanLocation()
func saveLocation()
func setLocation(latitude: Float, longitude: Float)
}

View File

@ -16,14 +16,16 @@ protocol LocationsListViewModeling: AnyObject {
var coordinator: LocationsListCoordination? { get set }
var locationsDidChangePublisher: PassthroughSubject<[Change], Never> { get }
var numberOfLocationSections: Int { get }
var viewStatusPublisher: Published<LocationsListViewStatus>.Publisher { get }
var numberOfSectionsInData: Int { get }
// MARK: Functions
func openAddLocation()
func loadLocations()
func numberOfDataItems(in section: Int) -> Int
func dataItem(at indexPath: IndexPath) -> Location
func location(at indexPath: IndexPath) -> Location
func numberOfLocations(in section: Int) -> Int
func openLocationsAdd()
func openWikipedia(at indexPath: IndexPath)
}

View File

@ -6,14 +6,30 @@
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Combine
import Core
import UIKit
import MapKit
class LocationsAddViewController: BaseViewController {
// MARK: Properties
var viewModel: LocationsAddViewModeling
private let viewModel: LocationsAddViewModeling
private var cancellables: Set<AnyCancellable> = []
// MARK: Outlets
private lazy var map = {
let map = MKMapView()
map.translatesAutoresizingMaskIntoConstraints = false
map.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tapOnMap)))
return map
}()
// MARK: Initialisers
@ -32,7 +48,91 @@ class LocationsAddViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Location Add"
setupBar()
setupView()
bindViewModel()
}
}
// MARK: - Helpers
private extension LocationsAddViewController {
// MARK: Functions
func bindViewModel() {
viewModel
.locationExistsPublisher
.receive(on: RunLoop.main)
.sink { locationExists in
self.navigationItem
.rightBarButtonItems?
.forEach { $0.isEnabled = locationExists }
}
.store(in: &cancellables)
}
func setupBar() {
title = "Add a location"
navigationController?.navigationBar.prefersLargeTitles = false
navigationController?.navigationBar.backgroundColor = .systemBackground
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.tintColor = .red
navigationItem.rightBarButtonItems = [
.init(
title: "Save",
style: .plain,
target: self,
action: #selector(saveButtonPressed)
),
.init(
title: "Clean",
style: .plain,
target: self,
action: #selector(cleanButtonPressed)
),
]
}
func setupView() {
view.addSubview(map)
NSLayoutConstraint.activate([
view.bottomAnchor.constraint(equalTo: map.bottomAnchor),
view.leadingAnchor.constraint(equalTo: map.leadingAnchor),
view.topAnchor.constraint(equalTo: map.topAnchor),
view.trailingAnchor.constraint(equalTo: map.trailingAnchor),
])
}
// MARK: Actions
@objc func cleanButtonPressed() {
map.removeAnnotations(map.annotations)
viewModel.cleanLocation()
}
@objc func saveButtonPressed() {
viewModel.saveLocation()
}
@objc func tapOnMap(recognizer: UITapGestureRecognizer) {
let tapOnView = recognizer.location(in: map)
let mapCoordinates = map.convert(tapOnView, toCoordinateFrom: map)
let annotation = MKPointAnnotation()
annotation.coordinate = mapCoordinates
map.removeAnnotations(map.annotations)
map.addAnnotation(annotation)
map.setCenter(mapCoordinates, animated: true)
viewModel.setLocation(
latitude: Float(mapCoordinates.latitude),
longitude: Float(mapCoordinates.longitude)
)
}
}

View File

@ -10,19 +10,82 @@ import Combine
import Core
class LocationsAddViewModel: ObservableObject {
// MARK: Properties
weak var coordinator: LocationsAddCoordination?
@Published private var location: Location?
@Published private var locationExists: Bool = false
private let saveLocalLocation = SaveLocalLocationUseCase()
// MARK: Initialisers
init(coordinator: LocationsAddCoordination) {
self.coordinator = coordinator
setupBindings()
}
}
// MARK: - LocationsAddViewModeling
extension LocationsAddViewModel: LocationsAddViewModeling {}
extension LocationsAddViewModel: LocationsAddViewModeling {
// MARK: Properties
var locationExistsPublisher: Published<Bool>.Publisher { $locationExists }
// MARK: Functions
func cleanLocation() {
location = nil
}
func saveLocation() {
guard let location else {
return
}
saveLocalLocation(
latitude: location.latitude,
longitude: location.longitude
)
coordinator?.closeLocationsAddScreen()
}
func setLocation(latitude: Float, longitude: Float) {
if location == nil {
location = .init(latitude: latitude, longitude: longitude)
} else {
location?.latitude = latitude
location?.longitude = longitude
}
}
}
// MARK: - Helpers
private extension LocationsAddViewModel {
// MARK: Functions
func setupBindings() {
$location
.map { $0 != nil }
.assign(to: &$locationExists)
}
}
// MARK: - Structs
private extension LocationsAddViewModel {
struct Location {
var latitude: Float
var longitude: Float
}
}

View File

@ -67,14 +67,14 @@ extension LocationsListViewController: UITableViewDataSource {
// MARK: Functions
func numberOfSections(in tableView: UITableView) -> Int {
viewModel.numberOfSectionsInData
viewModel.numberOfLocationSections
}
func tableView(
_ tableView: UITableView,
numberOfRowsInSection section: Int
) -> Int {
viewModel.numberOfDataItems(in: section)
viewModel.numberOfLocations(in: section)
}
func tableView(
@ -88,7 +88,7 @@ extension LocationsListViewController: UITableViewDataSource {
return .init()
}
let entity = viewModel.dataItem(at: indexPath)
let entity = viewModel.location(at: indexPath)
cell.update(
iconName: entity.source == .remote ? "network" : "house",
@ -104,7 +104,20 @@ extension LocationsListViewController: UITableViewDataSource {
// MARK: - UITableViewDelegate
extension LocationsListViewController: UITableViewDelegate {}
extension LocationsListViewController: UITableViewDelegate {
// MARK: Functions
func tableView(
_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath
) {
viewModel.openWikipedia(at: indexPath)
tableView.deselectRow(at: indexPath, animated: true)
}
}
// MARK: - Helpers
@ -161,10 +174,45 @@ private extension LocationsListViewController {
}
}
.store(in: &cancellables)
viewModel
.locationsDidChangePublisher
.sink(receiveValue: { [weak self] updates in
var movedToIndexPaths = [IndexPath]()
self?.table.performBatchUpdates({
for update in updates {
switch update {
case let .section(sectionUpdate):
switch sectionUpdate {
case let .inserted(index):
self?.table.insertSections([index], with: .automatic)
case let .deleted(index):
self?.table.deleteSections([index], with: .automatic)
}
case let .object(objectUpdate):
switch objectUpdate {
case let .inserted(at: indexPath):
self?.table.insertRows(at: [indexPath], with: .automatic)
case let .deleted(from: indexPath):
self?.table.deleteRows(at: [indexPath], with: .automatic)
case let .updated(at: indexPath):
self?.table.reloadRows(at: [indexPath], with: .automatic)
case let .moved(from: source, to: target):
self?.table.moveRow(at: source, to: target)
movedToIndexPaths.append(target)
}
}
}
}, completion: { done in
self?.table.reloadRows(at: movedToIndexPaths, with: .automatic)
})
})
.store(in: &cancellables)
}
@objc func addLocationPressed() {
viewModel.openAddLocation()
viewModel.openLocationsAdd()
}
}

View File

@ -6,7 +6,6 @@
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import CoreData
import Combine
import Dependency
import Foundation
@ -21,16 +20,11 @@ class LocationsListViewModel: ObservableObject {
// MARK: Properties
weak var coordinator: LocationsListCoordination?
private lazy var locationProvider = LocationProvider(managedContext: persistence.viewContext)
@Published private var viewStatus: LocationsListViewStatus = .initialised
private lazy var fetchedResultsController = NSFetchedResultsController(
fetchRequest: NSFetchRequest<Location>.allLocations(),
managedObjectContext: persistence.container.viewContext,
sectionNameKeyPath: nil,
cacheName: nil
)
private let loadRemoteLocations = LoadRemoteLocationsUseCase()
// MARK: Initialisers
@ -44,18 +38,15 @@ class LocationsListViewModel: ObservableObject {
// MARK: - LocationsListViewModeling
extension LocationsListViewModel: LocationsListViewModeling {
// MARK: Properties
var locationsDidChangePublisher: PassthroughSubject<[Persistence.Change], Never> { locationProvider.didChangePublisher }
var numberOfLocationSections: Int { locationProvider.numberOfSections }
var viewStatusPublisher: Published<LocationsListViewStatus>.Publisher { $viewStatus }
var numberOfSectionsInData: Int { fetchedResultsController.sections?.count ?? 0 }
// MARK: Functions
func openAddLocation() {
coordinator?.openAddLocation()
}
func loadLocations() {
Task {
do {
@ -63,7 +54,7 @@ extension LocationsListViewModel: LocationsListViewModeling {
try await loadRemoteLocations()
try fetchedResultsController.performFetch()
try locationProvider.fetch()
viewStatus = .loaded
} catch {
@ -72,19 +63,25 @@ extension LocationsListViewModel: LocationsListViewModeling {
}
}
func numberOfDataItems(in section: Int) -> Int {
guard
let sections = fetchedResultsController.sections,
sections.endIndex > section
else {
return 0
}
return sections[section].numberOfObjects
func location(at indexPath: IndexPath) -> Location {
locationProvider.location(at: indexPath)
}
func dataItem(at indexPath: IndexPath) -> Location {
fetchedResultsController.object(at: indexPath)
func numberOfLocations(in section: Int) -> Int {
locationProvider.numberOfLocationsInSection(section)
}
func openLocationsAdd() {
coordinator?.openLocationsAddScreen()
}
func openWikipedia(at indexPath: IndexPath) {
guard let url = locationProvider.location(at: indexPath).wikipediaPlacesURL else {
return
}
coordinator?.openWikipediaApp(with: url)
}
}

View File

@ -15,19 +15,21 @@ struct LoadRemoteLocationsUseCase {
// MARK: Properties
private let persistence: PersistenceService
private let remoteService: RemoteService
private let persistence: Persistence.Service
private let remoteService: Remote.Service
// MARK: Initialisers
init(
persistence: PersistenceService,
remoteService: RemoteService
persistence: Persistence.Service,
remoteService: Remote.Service
) {
self.persistence = persistence
self.remoteService = remoteService
}
// MARK: Functions
func callAsFunction() async throws {
let context = persistence.makeTaskContext()
let fetchRequest = NSFetchRequest<Persistence.Location>.allLocations()

View File

@ -0,0 +1,54 @@
//
// SaveLocalLocationUseCase.swift
// Locations
//
// Created by Javier Cicchelli on 12/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Dependency
import Persistence
struct SaveLocalLocationUseCase {
// MARK: Properties
private let persistence: Persistence.Service
// MARK: Initialisers
init(persistence: Persistence.Service) {
self.persistence = persistence
}
// MARK: Functions
func callAsFunction(
name: String? = nil,
latitude: Float,
longitude: Float
) {
let context = persistence.makeTaskContext()
let entity = Location(context: context)
entity.createdAt = .now
entity.name = name
entity.latitude = latitude
entity.longitude = longitude
entity.source = .local
persistence.save(context: context)
}
}
// MARK: - LoadRemoteLocationsUseCase+Initialisers
extension SaveLocalLocationUseCase {
init() {
@Dependency(\.persistence) var persistence
self.init(persistence: persistence)
}
}

View File

@ -456,7 +456,6 @@
41FCAA3721C844CB001D8411 /* ReadingListEntryCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41FCAA3521C844CB001D8411 /* ReadingListEntryCollectionViewController.swift */; };
41FCAA3821C844CB001D8411 /* ReadingListEntryCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41FCAA3521C844CB001D8411 /* ReadingListEntryCollectionViewController.swift */; };
41FCAA3921C844CB001D8411 /* ReadingListEntryCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41FCAA3521C844CB001D8411 /* ReadingListEntryCollectionViewController.swift */; };
46EB334829E1D204001D5EAF /* Shared in Frameworks */ = {isa = PBXBuildFile; productRef = 46EB334729E1D204001D5EAF /* Shared */; };
533AB8AE259792A9003A43D9 /* wikipedia-language-variants.json in Resources */ = {isa = PBXBuildFile; fileRef = 533AB8AD259792A9003A43D9 /* wikipedia-language-variants.json */; };
535F16D625CE11A300875AAD /* MWKDataStore+LanguageVariantMigration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 535F16D525CE11A300875AAD /* MWKDataStore+LanguageVariantMigration.swift */; };
53A575FA2602C845009835E6 /* WMFAppViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53A575F92602C845009835E6 /* WMFAppViewController+Extensions.swift */; };
@ -5776,7 +5775,6 @@
D8D553621DF1B63200B90177 /* QuartzCore.framework in Frameworks */,
D4E6D9121A5C65F9004916C1 /* CoreData.framework in Frameworks */,
D499143B181D51DE00E6073C /* CoreGraphics.framework in Frameworks */,
46EB334829E1D204001D5EAF /* Shared in Frameworks */,
D499143D181D51DE00E6073C /* UIKit.framework in Frameworks */,
D4991439181D51DE00E6073C /* Foundation.framework in Frameworks */,
041EFC371996A1F800B2CB28 /* MapKit.framework in Frameworks */,
@ -10079,7 +10077,6 @@
);
name = Wikipedia;
packageProductDependencies = (
46EB334729E1D204001D5EAF /* Shared */,
);
productName = "Wikipedia-iOS";
productReference = D4991435181D51DE00E6073C /* Wikipedia.app */;
@ -20146,10 +20143,6 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
46EB334729E1D204001D5EAF /* Shared */ = {
isa = XCSwiftPackageProductDependency;
productName = Shared;
};
67A770C7251BFE0400F94EF9 /* CocoaLumberjackSwift */ = {
isa = XCSwiftPackageProductDependency;
package = 67A770C6251BFE0400F94EF9 /* XCRemoteSwiftPackageReference "CocoaLumberjack" */;

View File

@ -12,6 +12,8 @@
02031EC929E60B29003C108C /* DependencyService+Keys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031EC829E60B29003C108C /* DependencyService+Keys.swift */; };
02031EE829E68D9B003C108C /* LoadingSpinnerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031EE729E68D9B003C108C /* LoadingSpinnerView.swift */; };
02031EEA29E6B495003C108C /* ErrorMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031EE929E6B495003C108C /* ErrorMessageView.swift */; };
02031F0829E75EF0003C108C /* SaveLocalLocationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031F0729E75EED003C108C /* SaveLocalLocationUseCase.swift */; };
02031F0A29E7645F003C108C /* Location+URLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02031F0929E7645F003C108C /* Location+URLs.swift */; };
4656CBC229E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4656CBC129E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift */; };
4656CBC829E6F2E400600EE6 /* LocationViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4656CBC729E6F2E400600EE6 /* LocationViewCell.swift */; };
46C3B7C629E5BF1500F8F57C /* LocationsListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3B7C529E5BF1500F8F57C /* LocationsListCoordinator.swift */; };
@ -22,12 +24,12 @@
46C3B7D829E5E55000F8F57C /* LocationsListCoordination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3B7D729E5E55000F8F57C /* LocationsListCoordination.swift */; };
46C3B7DC29E5ED2300F8F57C /* LocationsAddCoordination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3B7DB29E5ED2300F8F57C /* LocationsAddCoordination.swift */; };
46C3B7DE29E5ED2E00F8F57C /* LocationsAddCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C3B7DD29E5ED2E00F8F57C /* LocationsAddCoordinator.swift */; };
46DF736D29E82A1500AA6D21 /* UIApplication+Conformances.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46DF736C29E82A1500AA6D21 /* UIApplication+Conformances.swift */; };
46EB331B29E1CE04001D5EAF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46EB331A29E1CE04001D5EAF /* AppDelegate.swift */; };
46EB331F29E1CE04001D5EAF /* LocationsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46EB331E29E1CE04001D5EAF /* LocationsListViewController.swift */; };
46EB332729E1CE05001D5EAF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 46EB332629E1CE05001D5EAF /* Assets.xcassets */; };
46EB332A29E1CE05001D5EAF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 46EB332829E1CE05001D5EAF /* LaunchScreen.storyboard */; };
46EB334429E1D1EC001D5EAF /* Libraries in Frameworks */ = {isa = PBXBuildFile; productRef = 46EB334329E1D1EC001D5EAF /* Libraries */; };
46EB334629E1D1F0001D5EAF /* Shared in Frameworks */ = {isa = PBXBuildFile; productRef = 46EB334529E1D1F0001D5EAF /* Shared */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -130,6 +132,8 @@
02031EC829E60B29003C108C /* DependencyService+Keys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DependencyService+Keys.swift"; sourceTree = "<group>"; };
02031EE729E68D9B003C108C /* LoadingSpinnerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingSpinnerView.swift; sourceTree = "<group>"; };
02031EE929E6B495003C108C /* ErrorMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorMessageView.swift; sourceTree = "<group>"; };
02031F0729E75EED003C108C /* SaveLocalLocationUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SaveLocalLocationUseCase.swift; sourceTree = "<group>"; };
02031F0929E7645F003C108C /* Location+URLs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Location+URLs.swift"; sourceTree = "<group>"; };
4656CBC129E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadRemoteLocationsUseCase.swift; sourceTree = "<group>"; };
4656CBC729E6F2E400600EE6 /* LocationViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationViewCell.swift; sourceTree = "<group>"; };
46C3B7C529E5BF1500F8F57C /* LocationsListCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsListCoordinator.swift; sourceTree = "<group>"; };
@ -140,6 +144,7 @@
46C3B7D729E5E55000F8F57C /* LocationsListCoordination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsListCoordination.swift; sourceTree = "<group>"; };
46C3B7DB29E5ED2300F8F57C /* LocationsAddCoordination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsAddCoordination.swift; sourceTree = "<group>"; };
46C3B7DD29E5ED2E00F8F57C /* LocationsAddCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsAddCoordinator.swift; sourceTree = "<group>"; };
46DF736C29E82A1500AA6D21 /* UIApplication+Conformances.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Conformances.swift"; sourceTree = "<group>"; };
46EB325829E1BD5C001D5EAF /* Wikipedia.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Wikipedia.xcodeproj; path = Wikipedia/Wikipedia.xcodeproj; sourceTree = "<group>"; };
46EB331829E1CE04001D5EAF /* Locations.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Locations.app; sourceTree = BUILT_PRODUCTS_DIR; };
46EB331A29E1CE04001D5EAF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@ -148,7 +153,6 @@
46EB332929E1CE05001D5EAF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
46EB332B29E1CE05001D5EAF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
46EB333229E1CFD9001D5EAF /* Libraries */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Libraries; sourceTree = "<group>"; };
46EB333429E1D158001D5EAF /* Shared */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Shared; sourceTree = "<group>"; };
46EB334929E1D34B001D5EAF /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
46EB334A29E1D3C0001D5EAF /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -159,7 +163,6 @@
buildActionMask = 2147483647;
files = (
46EB334429E1D1EC001D5EAF /* Libraries in Frameworks */,
46EB334629E1D1F0001D5EAF /* Shared in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -178,6 +181,8 @@
isa = PBXGroup;
children = (
02031EC829E60B29003C108C /* DependencyService+Keys.swift */,
02031F0929E7645F003C108C /* Location+URLs.swift */,
46DF736C29E82A1500AA6D21 /* UIApplication+Conformances.swift */,
);
path = Extensions;
sourceTree = "<group>";
@ -223,6 +228,7 @@
isa = PBXGroup;
children = (
4656CBC129E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift */,
02031F0729E75EED003C108C /* SaveLocalLocationUseCase.swift */,
);
path = "Use Cases";
sourceTree = "<group>";
@ -266,7 +272,6 @@
46EB325029E1BBD1001D5EAF = {
isa = PBXGroup;
children = (
46EB333429E1D158001D5EAF /* Shared */,
46EB325729E1BCAB001D5EAF /* Apps */,
46EB334B29E1D3D2001D5EAF /* Others */,
46EB32EE29E1CD20001D5EAF /* Products */,
@ -380,7 +385,6 @@
name = Locations;
packageProductDependencies = (
46EB334329E1D1EC001D5EAF /* Libraries */,
46EB334529E1D1F0001D5EAF /* Shared */,
);
productName = Locations;
productReference = 46EB331829E1CE04001D5EAF /* Locations.app */;
@ -544,9 +548,12 @@
02031EBF29E5F949003C108C /* LocationsAddViewModeling.swift in Sources */,
4656CBC829E6F2E400600EE6 /* LocationViewCell.swift in Sources */,
46C3B7DE29E5ED2E00F8F57C /* LocationsAddCoordinator.swift in Sources */,
02031F0A29E7645F003C108C /* Location+URLs.swift in Sources */,
02031F0829E75EF0003C108C /* SaveLocalLocationUseCase.swift in Sources */,
02031EEA29E6B495003C108C /* ErrorMessageView.swift in Sources */,
46C3B7DC29E5ED2300F8F57C /* LocationsAddCoordination.swift in Sources */,
46C3B7D829E5E55000F8F57C /* LocationsListCoordination.swift in Sources */,
46DF736D29E82A1500AA6D21 /* UIApplication+Conformances.swift in Sources */,
46C3B7D629E5E50500F8F57C /* LocationsListViewModeling.swift in Sources */,
4656CBC229E6D33C00600EE6 /* LoadRemoteLocationsUseCase.swift in Sources */,
46C3B7CF29E5D00E00F8F57C /* LocationsAddViewModel.swift in Sources */,
@ -779,10 +786,6 @@
isa = XCSwiftPackageProductDependency;
productName = Libraries;
};
46EB334529E1D1F0001D5EAF /* Shared */ = {
isa = XCSwiftPackageProductDependency;
productName = Shared;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 46EB325129E1BBD1001D5EAF /* Project object */;

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "46EB331729E1CE04001D5EAF"
BuildableName = "Locations.app"
BlueprintName = "Locations"
ReferencedContainer = "container:DeepLinking.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "46EB331729E1CE04001D5EAF"
BuildableName = "Locations.app"
BlueprintName = "Locations"
ReferencedContainer = "container:DeepLinking.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "46EB331729E1CE04001D5EAF"
BuildableName = "Locations.app"
BlueprintName = "Locations"
ReferencedContainer = "container:DeepLinking.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -1,2 +1,44 @@
# Deep linking: Wikipedia
## App
The ultimate purpose of this application is to open the **Wikipedia** app in the right location when a user tap on one of the locations listed in the **Locations** app.
<center>
<video controls>
<source src="https://static.rock-n-code.com/mp4/deep-linking-app-demo.mp4" type="video/mp4">
</video>
</center>
Of course, to accomplish such goal the app therefore shows a list of locations (which are either fetched from a remote server or created by the user) and also, allows the user to add new location coordinates to this list by selecting them from a map.
## Features
In its current state, the **Locations** app does:
- [x] fetch locations from a remote server;
- [x] handle `loading`, `loaded` and `error` states reactively when loading data;
- [x] add locations manually to the list by obtaining locations from map;
- [x] clean map of selected location if required;
- [x] open the **Wikipedia** app when location is selected from a list;
While the **Wikipedia** app does:
- [x] open a location in the right position on the map of *Places* screen from a deep link;
## Design
<object data="https://static.rock-n-code.com/pdf/deep-linking-app-design.pdf" type="application/pdf" width="100%" height="800px">
<p>Unable to display a PDF file with some design considerations. Please <a href="https://static.rock-n-code.com/pdf/deep-linking-app-design.pdf">Download the file</a> instead.</p>
</object>
## Implementation
This application was built as a `UIKit` application given that the [assignment](https://repo.rock-n-code.com/rock-n-code/deep-linking-assignment/wiki/Assignment) explicitedly indicates the app should target the `iOS` platform (**iPhone** app only, in this particular case) and also, because it disallow the use of the `SwiftUI` framework. It is out of discussion that the `UIKit` framework has been battle-tested for over a decade now and [Apple](https://apple.com) keeps updating and adding features to it on a regular basis. The imperative nature of the framework, which is based in implementing how the `iOS` platform UI components should work, is perfectly suitable the developer who want absolute control over the UI, at a cost of maintaining platform-specific, more complex codebases.
With regards to the choice of framework to built this app, it also comes the question of the type of architecture pattern to use in it: for this particular case, and given the limitations of how the view controllers have been defined in the Apple platforms, [MVVM](https://en.wikipedia.org/wiki/Modelviewviewmodel)-C is the chosen architecrture as it facilitates the separation between logic and UI components while also, decoupling the navigation logic by using coordinates (and routers) from them.
Now that design patterns have been mentioned, in this exercise some well-known patterns are being used in some degree. For example, the *Singleton* pattern is used to initialise the `PersistenceService` service in the `Persistence` library. Both public and internal *Interfaces* that either describe an entity or how the entity should behave are used throughout this codebase, as this pattern is essential to create decoupled components that can be easily plugged as dependencies whenever needed as this forces the developer to think about (single) responsibilites and, as a consequence, these components are also easy to test in isolation as mocks, stubs and spies can be easily created out of them. Last, but definitely not least, the *Use cases* are a pattern from Android that basically execute a function based on some given input, and provides an output after that particular function is finished. This pattern is particularly useful to encapsulate in a simple way some certain logic from view models.
This application was built with scalability in terms of the codebase in mind, which tries to address how this codebase could grow in a controllable, organised manner. For this very reason, this application uses the [Swift Package Manager](https://www.swift.org/package-manager/) (or simply **SwiftPM**) to define the `Core`, `Dependency`, `Persistence` and `Remote` libraries of the `Library` package, that the **Locations** target should use extensively. These libraries focus on a specific purpose, and they can be self-contained, like in the case of the `Persistence` library that contains its own **CoreData** data model definitons and respective assets inside. Packages could use 3rd party dependencies if needed. This approach forces the developer to think about actual separation of concerns, as the different dependencies are grouped as independent, reusable building blocks, and to move the code into the SPM packages out of the main app target, reducing compiling time and overall weight of the application.
As a (indirect) consequence for the use of **SwiftPM** packages, the [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) pattern comes into question. I implemented my own simple **DI** mechanism that uses extensively the dynamic property wrapper functionality in the last versions of the [Swift](https://www.swift.org) language rather than using a 3rd party dependency for this case.

View File

@ -1,28 +0,0 @@
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Shared",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Shared",
targets: ["Shared"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Shared",
dependencies: []),
.testTarget(
name: "SharedTests",
dependencies: ["Shared"]),
]
)

View File

@ -1,6 +0,0 @@
public struct Shared {
public private(set) var text = "Hello, World!"
public init() {
}
}

View File

@ -1,11 +0,0 @@
import XCTest
@testable import Shared
final class SharedTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(Shared().text, "Hello, World!")
}
}

BIN
deep-linking-app-demo.mp4 Normal file

Binary file not shown.

BIN
deep-linking-app-design.pdf Normal file

Binary file not shown.