Core Data was used to delete favorite areas from the phone's memory.
//MARK: CoreDataManaging
protocol CoreDataManaging {
associatedtype Entity: NSManagedObject
associatedtype AddModel : Any
func fetchAll() throws -> [Entity]
func addEntity(model: AddModel) throws
func deleteEntity(id: Int16) throws
func isEntityExist(id: Int16) throws -> Bool
}CoreDataManaging was created in case Core Data is used for different entities in the future.
With this process, the basic operations to be performed have been abstracted.
In addition, thanks to the associatedtype Entity: NSManagedObject definition, classes that implement this protocol specify the entity they are working with. Thus, a single protocol can be reused for all entity types.
Core Data entities are not suitable for being directly transferred to application layers. Therefore, external data containers (DTO, AddModel) are generally used. With the associatedtype AddModel, a different data model can be defined for each entity.
By managing location-related operations with a manager, a more readable and testable structure was created.
//MARK: LocationPermissonState
/// Represents the state of location permission.
enum LocationPermissonState {
case successful /// User has granted location permission.
case notDetermined /// User has not made a choice regarding location permission yet.
case denied /// User has denied location permission.
}
//MARK: FocusUserLocationState
/// Represents the state of focusing on the user's location.
enum FocusUserLocationState {
case focus /// Map can focus on user's location.
case notDetermined /// Permission state is not determined yet.
case denied /// Cannot focus due to denied permission.
}
//MARK: MapLocationManagerDelegate
/// Protocol to handle location-related delegate callbacks.
protocol MapLocationManagerDelegate: AnyObject {
/// Called when the location permission state changes.
/// - Parameter state: The current permission state.
func locationPermisson(state:LocationPermissonState)
/// Called to indicate the ability to focus on the user's location.
/// - Parameter state: The current focus state.
func focusUserLocation(state:FocusUserLocationState)
/// Called when a new location is received.
/// - Parameter location: A tuple containing latitude and longitude.
func didUpdateLocation(_ location: (lat:Double,lng:Double))
}
/// Provides a default implementation to make `didUpdateLocation` optional.
extension MapLocationManagerDelegate {
func didUpdateLocation(_ location: (lat:Double,lng:Double)){
}
}
protocol MapLocationManagerProtocol {
var delegate: MapLocationManagerDelegate? {get set}
/// Requests location permission from the user.
func requestLocationAccess()
/// Checks whether the app can focus on the user's location based on current permission status.
func focusUserLocationAuthorization()
/// Calculates the distance between two geographic points.
/// - Parameters:
/// - point: The first coordinate (latitude, longitude).
/// - target: The second coordinate (latitude, longitude).
/// - Returns: The distance in meters.
func calculateDistance(point:(lat:Double,lng:Double),target:(lat:Double,lng:Double)) -> Double
}- ViewKit
- managerkit
- CoreKit
- FactoryKit
- ViewControllerAbleKit
- SplashModule
- HomeModule
- DetailModule
- FavoritesModule
- LocationMapModule
- CityMapModule
- Alamofire
- Kingfisher
- SnapKit
- VIPER used
- Protocol Oriented Programming
- Unit Test
- MapKit
##Language
- Türkçe
- English
| |
|
| |
|
| |
| |
|