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

Reduced minimum version #2

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "iOSCommonLibraries",
platforms: [.iOS(.v15), .macOS(.v12)],
platforms: [.iOS(.v13), .macOS(.v12)],
products: [
.library(
name: "iOSCommonLibraries",
Expand Down
95 changes: 95 additions & 0 deletions Sources/iOS-Common-Libraries/Extensions/Array+Update.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// File.swift
//
//
// Created by Nick Kibysh on 07/07/2023.
//

import Foundation

extension Array {
public func replaceOrAppend(_ newElement: Element, firstWhere closure: (Element) -> Bool) -> [Element] {
var newArray = self

for e in newArray.enumerated() {
if closure(e.element) {
newArray[e.offset] = newElement
return newArray
}
}

newArray.append(newElement)
return newArray
}

@discardableResult
mutating public func replacedOrAppended(_ newElement: Element, firstWhere closure: (Element) -> Bool) -> Bool {
for e in self.enumerated() {
if closure(e.element) {
self[e.offset] = newElement
return true
}
}

self.append(newElement)
return false
}
}

extension Array where Element: Equatable {
public func replaceOrAppend(_ newElement: Element) -> [Element] {
var newArray = self

for e in newArray.enumerated() {
if e.element == newElement {
newArray[e.offset] = newElement
return newArray
}
}

newArray.append(newElement)
return newArray
}

@discardableResult
mutating public func replacedOrAppended(_ newElement: Element) -> Bool {
for e in self.enumerated() {
if e.element == newElement {
self[e.offset] = newElement
return true
}
}

self.append(newElement)
return false
}
}

extension Array {
public func replaceOrAppend<V: Equatable>(_ newElement: Element, compareBy keyPath: KeyPath<Element, V>) -> [Element] {
var newArray = self

for e in newArray.enumerated() {
if e.element[keyPath: keyPath] == newElement[keyPath: keyPath] {
newArray[e.offset] = newElement
return newArray
}
}

newArray.append(newElement)
return newArray
}

@discardableResult
mutating public func replacedOrAppended<V: Equatable>(_ newElement: Element, compareBy keyPath: KeyPath<Element, V>) -> Bool {
for e in self.enumerated() {
if e.element[keyPath: keyPath] == newElement[keyPath: keyPath] {
self[e.offset] = newElement
return true
}
}

self.append(newElement)
return false
}
}
1 change: 1 addition & 0 deletions Sources/iOS-Common-Libraries/Extensions/Color/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public extension Color {
// MARK: uiColor

#if os(iOS) || targetEnvironment(macCatalyst)
@available(iOS 14.0, *)
var uiColor: UIColor {
UIColor(self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import Foundation
import os

extension Logger {

extension L {
static let iOSCommonLibrarySubsystem = "com.nordicsemi.iOS-Common-Libraries"

// MARK: - Init
Expand All @@ -19,6 +18,6 @@ extension Logger {
}

init(category: String) {
self.init(subsystem: Logger.iOSCommonLibrarySubsystem, category: category)
self.init(subsystem: L.iOSCommonLibrarySubsystem, category: category)
}
}
4 changes: 4 additions & 0 deletions Sources/iOS-Common-Libraries/Extensions/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public extension View {

// MARK: - NavBar

@available(iOS 14.0, *)
func setTitle(_ title: String) -> some View {
#if os(iOS)
return navigationBarTitle(title, displayMode: .inline)
Expand All @@ -44,6 +45,7 @@ public extension View {

// MARK: - NavigationView

@available(iOS 14.0, *)
@ViewBuilder
func wrapInNavigationViewForiOS(with color: Color) -> some View {
#if os(iOS)
Expand Down Expand Up @@ -72,6 +74,7 @@ public extension View {

public extension Picker {

@available(iOS 14.0, *)
@ViewBuilder
func setAsComboBoxStyle() -> some View {
self
Expand Down Expand Up @@ -100,6 +103,7 @@ public extension NavigationView {
#endif
}

@available(iOS 14.0, *)
func setupNavBarBackground(with color: Color) -> NavigationView {
#if os(iOS)
let appearance = UINavigationBarAppearance()
Expand Down
10 changes: 5 additions & 5 deletions Sources/iOS-Common-Libraries/Network/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class Network {

// MARK: - Properties

private lazy var logger = Logger(Self.self)
private lazy var logger = L(Self.self)
private lazy var imageCache = Cache<URL, Image>()
private lazy var session = URLSession(configuration: .multiPathEnabled)

Expand Down Expand Up @@ -50,7 +50,7 @@ public extension Network {

func isReachable() -> Bool {
guard let reachability = reachability else {
logger.error("\(#function): Nil reachability property.")
logger.e("\(#function): Nil reachability property.")
return false
}

Expand All @@ -62,7 +62,7 @@ public extension Network {
let canConnectAutomatically = flags.contains(.connectionOnDemand) || flags.contains(.connectionOnTraffic)
let canConnectWithoutIntervention = canConnectAutomatically && !flags.contains(.interventionRequired)
let result = isReachable && (!connectionRequired || canConnectWithoutIntervention)
logger.debug("\(#function): \(result)")
logger.d("\(#function): \(result)")
return isReachable && (!connectionRequired || canConnectWithoutIntervention)
}

Expand All @@ -72,7 +72,7 @@ public extension Network {
let sessionRequestPublisher = session.dataTaskPublisher(for: request)
.tryMap() { [logger] element -> Data in
#if DEBUG
logger.debug("\(element.response)")
logger.d("\(element.response)")
#endif

guard let httpResponse = element.response as? HTTPURLResponse else {
Expand All @@ -87,7 +87,7 @@ public extension Network {
default: // Assume Error.
if let responseDataAsString = String(data: element.data, encoding: .utf8) {
#if DEBUG
logger.debug("\(request): \(responseDataAsString)")
logger.d("\(request): \(responseDataAsString)")
#endif
throw URLError(.cannotParseResponse)
} else {
Expand Down
Loading