Skip to content

Commit 8a25ca7

Browse files
committed
Release 1.0.0.
1 parent aeb33a0 commit 8a25ca7

22 files changed

Lines changed: 474 additions & 32 deletions

Package.swift

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1-
// swift-tools-version: 5.7
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
// swift-tools-version:5.7
32

43
import PackageDescription
54

65
let package = Package(
76
name: "CoreModule",
7+
platforms: [
8+
.iOS(.v14)
9+
],
810
products: [
9-
// Products define the executables and libraries a package produces, and make them visible to other packages.
1011
.library(
1112
name: "CoreModule",
12-
targets: ["CoreModule"]),
13-
],
14-
dependencies: [
15-
// Dependencies declare other packages that this package depends on.
16-
// .package(url: /* package url */, from: "1.0.0"),
13+
targets: ["CoreModule"]
14+
)
1715
],
1816
targets: [
19-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
20-
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2117
.target(
2218
name: "CoreModule",
23-
dependencies: []),
24-
.testTarget(
25-
name: "CoreModuleTests",
26-
dependencies: ["CoreModule"]),
19+
path: "Source"
20+
)
2721
]
2822
)

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# CoreModule
22

3-
A description of this package.
3+
Core module for iOS projects.
4+
5+
Contents
6+
7+
* Core protocols
8+
* Logging framework
9+
* Some extensions for basic Swift types
10+
* Some UIKit extensions
11+
* HTTP client

Source/Array+Core.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Array+Core.swift
3+
// ReTodoList
4+
//
5+
// Created by Maksim Ivanov on 21.02.2023.
6+
//
7+
8+
extension Array {
9+
10+
public subscript(safeIndex index: Int) -> Element? {
11+
guard index >= 0, index < endIndex else {
12+
return nil
13+
}
14+
15+
return self[index]
16+
}
17+
}

Source/Builder.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Builder.swift
3+
// PersonalDictionary
4+
//
5+
// Created by Maxim Ivanov on 27.10.2022.
6+
//
7+
8+
import UIKit
9+
10+
public protocol ViewBuilder {
11+
12+
func build() -> UIView
13+
}
14+
15+
public protocol ViewControllerBuilder {
16+
17+
func build() -> UIViewController
18+
}
19+
20+
public protocol SearchControllerBuilder {
21+
22+
func build() -> UISearchController
23+
}

Source/CoreRouter.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// CoreRouter.swift
3+
// CoreModule
4+
//
5+
// Created by Maxim Ivanov on 16.12.2021.
6+
//
7+
8+
public protocol CoreRouter {
9+
10+
func navigate()
11+
}

Source/Date+Core.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Date+Core.swift
3+
// ReTodoList
4+
//
5+
// Created by Maksim Ivanov on 12.08.2022.
6+
//
7+
8+
import Foundation
9+
10+
extension Date {
11+
12+
public var dMMMMyyyy: String {
13+
let dateFormatter = DateFormatter()
14+
dateFormatter.dateFormat = "d MMMM yyyy"
15+
16+
return dateFormatter.string(from: self)
17+
}
18+
19+
public var integer: Int {
20+
Int(timeIntervalSince1970)
21+
}
22+
}

Source/Logger/LogLevel.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// CoreRouter.swift
3+
// CoreModule
4+
//
5+
// Created by Maxim Ivanov on 16.12.2021.
6+
//
7+
8+
public enum LogLevel: String {
9+
case debug = "DEBUG"
10+
case info = "INFO"
11+
case warn = "WARN ⚠️"
12+
case error = "ALERT ❌"
13+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// CoreRouter.swift
3+
// CoreModule
4+
//
5+
// Created by Maxim Ivanov on 16.12.2021.
6+
//
7+
8+
import Foundation
9+
10+
extension Logger {
11+
12+
public func debug(_ message: String) {
13+
log(message, level: .debug)
14+
}
15+
16+
public func logWithContext(_ message: String,
17+
level: LogLevel = .info,
18+
file: String = #file,
19+
function: String = #function,
20+
line: Int = #line) {
21+
guard isDevelopment() else { return }
22+
23+
log(message, level: level, file: file, function: function, line: line)
24+
}
25+
26+
public func errorWithContext(_ error: Error,
27+
file: String = #file,
28+
function: String = #function,
29+
line: Int = #line) {
30+
guard isDevelopment() else { return }
31+
32+
log("\(error)", level: .error, file: file, function: function, line: line)
33+
}
34+
35+
public func logState<State>(actionName: String,
36+
_ state: State,
37+
file: String = #file,
38+
function: String = #function,
39+
line: Int = #line) {
40+
guard isDevelopment() else { return }
41+
let text = "\(actionName) result:\n\(state)"
42+
43+
log(text, level: .info, file: file, function: function, line: line)
44+
}
45+
46+
public func logSending<T>(_ object: T,
47+
toModelStream modelStreamName: String,
48+
file: String = #file,
49+
function: String = #function,
50+
line: Int = #line) {
51+
guard isDevelopment() else { return }
52+
let text = "Sending \(type(of: object)) = \(object) to the \(modelStreamName) model stream."
53+
54+
log(text, level: .info, file: file, function: function, line: line)
55+
}
56+
57+
public func logReceiving<T>(_ object: T,
58+
fromModelStream modelStreamName: String,
59+
file: String = #file,
60+
function: String = #function,
61+
line: Int = #line) {
62+
guard isDevelopment() else { return }
63+
let text = "Received \(type(of: object)) = \(object) from the \(modelStreamName) model stream."
64+
65+
log(text, level: .info, file: file, function: function, line: line)
66+
}
67+
68+
public func log(installedFeatureName: String) {
69+
debug("The \(installedFeatureName) feature has been installed.")
70+
}
71+
72+
public func log(dismissedFeatureName: String) {
73+
debug("The \(dismissedFeatureName) feature has been dismissed.")
74+
}
75+
76+
private func log(_ text: String, level: LogLevel, file: String, function: String, line: Int) {
77+
let description = "\((file as NSString).lastPathComponent) line:\(line) \(function)"
78+
79+
log("\(text) -> \(description)", level: level)
80+
}
81+
}

Source/Logger/Logger.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Logger.swift
3+
// CoreModule
4+
//
5+
// Created by Maxim Ivanov on 24.03.2023.
6+
//
7+
8+
public protocol Logger {
9+
10+
func log(_ message: String, level: LogLevel)
11+
}

Source/Logger/LoggerImpl.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// LoggerImpl.swift
3+
// CoreModule
4+
//
5+
// Created by Maxim Ivanov on 24.03.2023.
6+
//
7+
8+
import os
9+
10+
public final class LoggerImpl: CoreModule.Logger {
11+
12+
private let logger: os.Logger
13+
14+
public init(category: String) {
15+
logger = os.Logger(subsystem: "General", category: category)
16+
}
17+
18+
public func log(_ message: String, level: LogLevel) {
19+
guard isDevelopment() else { return }
20+
21+
logger.log(level: level.getOsLogLevel(), "[\(level.rawValue)] \(message)")
22+
}
23+
}
24+
25+
extension LogLevel {
26+
27+
func getOsLogLevel() -> OSLogType {
28+
switch self {
29+
case .debug:
30+
return .debug
31+
32+
case .info:
33+
return .default
34+
35+
case .warn:
36+
return .error
37+
38+
case .error:
39+
return .fault
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)