Skip to content

Commit

Permalink
auto corrected lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbarela committed Dec 19, 2023
1 parent 65417b4 commit 6d74193
Show file tree
Hide file tree
Showing 113 changed files with 301 additions and 338 deletions.
3 changes: 1 addition & 2 deletions Marlin/Marlin/Conversions/GeoJSONExportable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension GeoJSONExportable {

for property in Self.properties {
if let gjObject = self as? NSObject, let value = gjObject.value(forKey: property.key) {
switch (property.type) {
switch property.type {
case .location:
print("ignore")
default:
Expand Down Expand Up @@ -108,4 +108,3 @@ extension GeoJSONExportable {
return nil
}
}

40 changes: 20 additions & 20 deletions Marlin/Marlin/CoreData/NSManagedObjectContext+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import Foundation
import CoreData

extension NSManagedObjectContext {
//Execute fetch request
// Execute fetch request
func fetch<T: NSManagedObject>(request: NSFetchRequest<T>) -> [T]? {
let fetchedResult = try? self.fetch(request)
return fetchedResult
}
func fetchObjects <T: NSManagedObject>(_ entityClass:T.Type,
func fetchObjects <T: NSManagedObject>(_ entityClass: T.Type,
sortBy: [NSSortDescriptor]? = nil,
fetchLimit:Int? = nil,
predicate: NSPredicate? = nil) throws-> [T]? {
fetchLimit: Int? = nil,
predicate: NSPredicate? = nil) throws -> [T]? {
guard let request: NSFetchRequest<T> = entityClass.fetchRequest() as? NSFetchRequest<T> else {
return nil
}
Expand All @@ -30,41 +30,41 @@ extension NSManagedObjectContext {
return fetchedResult
}

//Returns the count of objects for the given entity
func countOfObjects<T: NSManagedObject>(_ entityClass:T.Type) throws -> Int? {
// Returns the count of objects for the given entity
func countOfObjects<T: NSManagedObject>(_ entityClass: T.Type) throws -> Int? {
guard let request: NSFetchRequest<T> = entityClass.fetchRequest() as? NSFetchRequest<T> else {
return nil
}
// let request: NSFetchRequest<T> = fetchRequest(for: entityClass)
return try self.count(for: request)
}
//Returns first object after executing fetchObjects method with given sort and predicates
func fetchFirst <T: NSManagedObject>(_ entityClass:T.Type,
// Returns first object after executing fetchObjects method with given sort and predicates
func fetchFirst <T: NSManagedObject>(_ entityClass: T.Type,
sortBy: [NSSortDescriptor]? = nil,
predicate: NSPredicate? = nil) throws-> T? {
predicate: NSPredicate? = nil) throws -> T? {
let result = try self.fetchObjects(entityClass, sortBy: sortBy, fetchLimit: 1, predicate: predicate)
return result?.first
}
//Helper method to fetch first object with given key value pair.
func fetchFirst<T: NSManagedObject>(_ entityClass:T.Type,
key:String,
value:String) -> T? {
let predicate = NSPredicate(format: "%K = %@", key,value)
// Helper method to fetch first object with given key value pair.
func fetchFirst<T: NSManagedObject>(_ entityClass: T.Type,
key: String,
value: String) -> T? {
let predicate = NSPredicate(format: "%K = %@", key, value)
return try? self.fetchFirst(entityClass, sortBy: nil, predicate: predicate)
}

func fetchFirst<T: NSManagedObject>(_ entityClass:T.Type,
key:String,
value:Int64) -> T? {
let predicate = NSPredicate(format: "%K = %d", key,value)
func fetchFirst<T: NSManagedObject>(_ entityClass: T.Type,
key: String,
value: Int64) -> T? {
let predicate = NSPredicate(format: "%K = %d", key, value)
return try? self.fetchFirst(entityClass, sortBy: nil, predicate: predicate)
}

func fetchAll<T: NSManagedObject>(_ entityClass:T.Type) -> [T]? {
func fetchAll<T: NSManagedObject>(_ entityClass: T.Type) -> [T]? {
return try? self.fetchObjects(entityClass)
}

func truncateAll<T: NSManagedObject>(_ entityClass:T.Type) -> Bool {
func truncateAll<T: NSManagedObject>(_ entityClass: T.Type) -> Bool {
let request: NSFetchRequest<NSFetchRequestResult> = entityClass.fetchRequest() as NSFetchRequest<NSFetchRequestResult>
let deleteRequest = NSBatchDeleteRequest(fetchRequest: request)

Expand Down
23 changes: 10 additions & 13 deletions Marlin/Marlin/CoreData/Persistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protocol PersistentStore {
func fetchFirst<T: NSManagedObject>(_ entityClass: T.Type,
sortBy: [NSSortDescriptor]?,
predicate: NSPredicate?,
context: NSManagedObjectContext?) throws-> T?
context: NSManagedObjectContext?) throws -> T?
func fetch<ResultType: NSFetchRequestResult>(fetchRequest: NSFetchRequest<ResultType>) throws -> [ResultType]
func perform(_ block: @escaping () -> Void)
func save() throws
Expand Down Expand Up @@ -70,10 +70,10 @@ class MockPersistentStore: PersistentStore {
return NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
}

func fetchFirst<T: NSManagedObject>(_ entityClass:T.Type,
func fetchFirst<T: NSManagedObject>(_ entityClass: T.Type,
sortBy: [NSSortDescriptor]? = nil,
predicate: NSPredicate? = nil,
context: NSManagedObjectContext? = nil) throws-> T? {
context: NSManagedObjectContext? = nil) throws -> T? {
return nil
}

Expand Down Expand Up @@ -128,7 +128,7 @@ class CoreDataPersistentStore: PersistentStore {
func fetchFirst<T: NSManagedObject>(_ entityClass: T.Type,
sortBy: [NSSortDescriptor]? = nil,
predicate: NSPredicate? = nil,
context: NSManagedObjectContext? = nil) throws-> T? {
context: NSManagedObjectContext? = nil) throws -> T? {

return try (context ?? container.viewContext).fetchFirst(entityClass, sortBy: sortBy, predicate: predicate)
}
Expand Down Expand Up @@ -316,7 +316,7 @@ class CoreDataPersistentStore: PersistentStore {
_container = initializeContainer()
NotificationCenter.default
.publisher(for: .NSPersistentStoreRemoteChange)
.sink { value in
.sink { _ in
self.fetchPersistentHistoryTransactionsAndChanges()
}
.store(in: &subscriptions)
Expand All @@ -332,8 +332,7 @@ class CoreDataPersistentStore: PersistentStore {
if let forceReloadDate = forceReloadDate, lastLoadDate < forceReloadDate, !inMemory {
NSLog("Delete and reload")
if !inMemory {
do
{
do {
let storeURL: URL = NSPersistentContainer
.defaultDirectoryURL()
.appendingPathComponent("Marlin.sqlite")
Expand All @@ -346,9 +345,7 @@ class CoreDataPersistentStore: PersistentStore {
.defaultDirectoryURL()
.appendingPathComponent("Marlin.sqlite-shm")
try FileManager.default.removeItem(atPath: shmURL.path)
}
catch
{
} catch {
print(error.localizedDescription)
}
}
Expand Down Expand Up @@ -455,7 +452,7 @@ class CoreDataPersistentStore: PersistentStore {

private func mergePersistentHistoryChanges(from history: [NSPersistentHistoryTransaction]) {
let entityMap: [String?: String] =
MSI.shared.masterDataList.reduce([String?:String]()) { (partialResult, importable) -> [String?:String] in
MSI.shared.masterDataList.reduce([String?: String]()) { (partialResult, importable) -> [String?: String] in
var partialResult = partialResult
partialResult[importable.entity().name] = importable.key
return partialResult
Expand All @@ -465,8 +462,8 @@ class CoreDataPersistentStore: PersistentStore {
/// - Tag: mergeChanges
let viewContext = container.viewContext
viewContext.perform {
var updateCounts: [String? : Int] = [:]
var insertCounts: [String? : Int] = [:]
var updateCounts: [String?: Int] = [:]
var insertCounts: [String?: Int] = [:]
for transaction in history {
let notif = transaction.objectIDNotification()
let inserts: Set<NSManagedObjectID> =
Expand Down
8 changes: 4 additions & 4 deletions Marlin/Marlin/DataSources/DFRS/DFRS+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ extension DFRS: Locatable {
comment: "Radio Direction Finders and Radar station data source display name")
static var key: String = "dfrs"
static var metricsKey: String = "dfrs"
static var imageName: String? = nil
static var imageName: String?
static var systemImageName: String? = "antenna.radiowaves.left.and.right.circle"
static var color: UIColor = UIColor(argbValue: 0xFFFFB300)
static var imageScale = UserDefaults.standard.imageScale(key) ?? 0.66

static var defaultSort: [DataSourceSortParameter] = [
DataSourceSortParameter(
property:DataSourceProperty(
property: DataSourceProperty(
name: "Area Name",
key: #keyPath(DFRS.areaName),
type: .string),
ascending: true),
DataSourceSortParameter(
property:DataSourceProperty(
property: DataSourceProperty(
name: "Station Number",
key: #keyPath(DFRS.stationNumber),
type: .double),
Expand All @@ -72,7 +72,7 @@ extension DFRS: Locatable {
DataSourceProperty(name: "Rx Latitude", key: #keyPath(DFRS.rxLatitude), type: .latitude),
DataSourceProperty(name: "Rx Longitude", key: #keyPath(DFRS.rxLongitude), type: .longitude),
DataSourceProperty(name: "Tx Latitude", key: #keyPath(DFRS.txLatitude), type: .latitude),
DataSourceProperty(name: "Tx Longitude", key: #keyPath(DFRS.txLongitude), type: .longitude),
DataSourceProperty(name: "Tx Longitude", key: #keyPath(DFRS.txLongitude), type: .longitude)
]

static var dateFormatter: DateFormatter {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/Marlin/DataSources/DFRS/Views/DFRSDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct DFRSDetailView: View {
Text(areaNotes)
.secondary()
.lineLimit(8)
.frame(maxWidth:.infinity)
.frame(maxWidth: .infinity)
.padding(.all, 16)
.card()
}
Expand All @@ -76,7 +76,7 @@ struct DFRSDetailView: View {
.dataSourceSection()
}
.dataSourceDetailList()
.onChange(of: dfrs, perform: { newValue in
.onChange(of: dfrs, perform: { _ in
predicate = NSPredicate(format: "stationNumber == %@", dfrs.stationNumber ?? "")
})
.onAppear {
Expand Down
7 changes: 3 additions & 4 deletions Marlin/Marlin/DataSources/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension BatchImportable {

class DataSourceImageCache {
static let shared = DataSourceImageCache()
var images: [String : UIImage] = [:]
var images: [String: UIImage] = [:]

func getCachedImage(dataSourceKey: String, zoomLevel: Int) -> UIImage? {
return images["\(dataSourceKey)\(zoomLevel)"]
Expand All @@ -67,7 +67,7 @@ enum DataSourcePropertyType: Codable {
case longitude

func defaultComparison() -> DataSourceFilterComparison {
switch (self) {
switch self {

case .string, .enumeration, .int, .double, .float, .boolean, .latitude, .longitude:
return .equals
Expand All @@ -79,7 +79,7 @@ enum DataSourcePropertyType: Codable {
}

func comparisons() -> [DataSourceFilterComparison] {
switch (self) {
switch self {
case .date:
return DataSourceFilterComparison.dateSubset()
case .enumeration:
Expand Down Expand Up @@ -179,4 +179,3 @@ protocol DataSourceViewBuilder: DataSource {
@ViewBuilder
var summary: Summary { get }
}

1 change: 0 additions & 1 deletion Marlin/Marlin/DataSources/DataSourceIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ struct DataSourceIcon: View {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ extension DifferentialGPSStationModel: DataSource {
DataSourceProperty(name: "Preceding Note", key: #keyPath(DifferentialGPSStation.precedingNote), type: .string),
DataSourceProperty(name: "Post Note",
key: #keyPath(DifferentialGPSStation.postNote),
type: .string),
type: .string)

]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class DownloadManager: NSObject {
}
}
if let destinationUrl = URL(string: downloadable.savePath) {
if (FileManager().fileExists(atPath: destinationUrl.path)) {
if FileManager().fileExists(atPath: destinationUrl.path) {
PersistenceController.current.perform {
downloadable.objectWillChange.send()
downloadable.isDownloading = false
Expand Down Expand Up @@ -148,7 +148,7 @@ extension DownloadManager: URLSessionDownloadDelegate {

guard let httpResponse = downloadTask.response as? HTTPURLResponse,
(200...299).contains(httpResponse.statusCode) else {
print ("server error code \(downloadTask.response.debugDescription)")
print("server error code \(downloadTask.response.debugDescription)")
if let httpResponse = downloadTask.response as? HTTPURLResponse {
downloadable.managedObjectContext?.perform {
downloadable.objectWillChange.send()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ struct ElectronicPublicationProperties: Decodable {
self.sectionName = try? values.decode(String.self, forKey: .sectionName)
self.sectionOrder = try? values.decode(Int.self, forKey: .sectionOrder)

var parsedPubsecLastModifiedDate: Date? = nil
var parsedPubsecLastModifiedDate: Date?
if let dateString = try? values.decode(String.self, forKey: .pubsecLastModified) {
if let date = ElectronicPublication.dateFormatter.date(from: dateString) {
parsedPubsecLastModifiedDate = date
}
}
self.pubsecLastModified = parsedPubsecLastModifiedDate

var parsedSectionLastModifiedDate: Date? = nil
var parsedSectionLastModifiedDate: Date?
if let dateString = try? values.decode(String.self, forKey: .sectionLastModified) {
if let date = ElectronicPublication.dateFormatter.date(from: dateString) {
parsedSectionLastModifiedDate = date
}
}
self.sectionLastModified = parsedSectionLastModifiedDate

var parsedUploadTime: Date? = nil
var parsedUploadTime: Date?
if let dateString = try? values.decode(String.self, forKey: .uploadTime) {
if let date = ElectronicPublication.dateFormatter.date(from: dateString) {
parsedUploadTime = date
Expand Down
4 changes: 2 additions & 2 deletions Marlin/Marlin/DataSources/Light/FogSignalImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import UIKit

class FogSignalImage : UIImage {
class FogSignalImage: UIImage {

convenience init?(frame: CGRect, arcWidth: CGFloat? = nil, arcRadius: CGFloat? = nil, drawArcs: Bool = true, darkMode: Bool = false) {
let strokeWidth = 0.5
Expand All @@ -17,7 +17,7 @@ class FogSignalImage : UIImage {
let finalArcWidth = arcWidth ?? 2.0

let circleColor = Light.raconColor
let labelColor = UIColor.label.resolvedColor(with:UITraitCollection(traitsFrom: [.init(userInterfaceStyle: darkMode ? .dark : .light)]))
let labelColor = UIColor.label.resolvedColor(with: UITraitCollection(traitsFrom: [.init(userInterfaceStyle: darkMode ? .dark : .light)]))

let renderer = UIGraphicsImageRenderer(size: frame.size)
let image = renderer.image { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Light: DataSourceViewBuilder {
}

var summary: some DataSourceSummaryView {
LightSummaryView(light: LightModel(light:self))
LightSummaryView(light: LightModel(light: self))
}
}

Expand Down
3 changes: 1 addition & 2 deletions Marlin/Marlin/DataSources/Light/Light+Decodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ struct LightsProperties: Codable {
for component in ["latdeg", "latminutes", "latseconds", "latdirection"] {
let nsrange = match.range(withName: component)
if nsrange.location != NSNotFound,
let range = Range(nsrange, in: position)
{
let range = Range(nsrange, in: position) {
if component == "latdeg" {
latitude = Double(position[range]) ?? 0.0
} else if component == "latminutes" {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/Marlin/DataSources/Light/LightColorImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class LightImage {
}
}

class LightColorImage : UIImage {
class LightColorImage: UIImage {

convenience init?(
frame: CGRect,
Expand Down Expand Up @@ -312,7 +312,7 @@ class LightColorImage : UIImage {
let endDegrees = sector.endDegrees > sector.startDegrees ? sector.endDegrees : sector.endDegrees + 360.0
let midPointAngle = CGFloat(sector.startDegrees) + CGFloat(endDegrees - sector.startDegrees) / 2.0
var textRadius = radius
if let arcWidth = arcWidth{
if let arcWidth = arcWidth {
textRadius -= arcWidth * 1.75
} else {
textRadius -= size.height
Expand Down
Loading

0 comments on commit 6d74193

Please sign in to comment.