Skip to content

Commit 0c00ecd

Browse files
authored
Заменил все принты на логгер (#214)
* Заменил все принты на logger - Полезная статья: https://www.avanderlee.com/debugging/oslog-unified-logging/ - Полезное видео 1: https://developer.apple.com/videos/play/wwdc2020/10168/ - Полезное видео 2: https://developer.apple.com/wwdc23/10226 * Запустил форматирование * Поднял версию до 3.5.4
1 parent 958fb79 commit 0c00ecd

File tree

11 files changed

+43
-29
lines changed

11 files changed

+43
-29
lines changed

SwiftUI-WorkoutApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@
10831083
"$(inherited)",
10841084
"@executable_path/Frameworks",
10851085
);
1086-
MARKETING_VERSION = 3.5.3;
1086+
MARKETING_VERSION = 3.5.4;
10871087
PRODUCT_BUNDLE_IDENTIFIER = com.FGU.WorkOut;
10881088
PRODUCT_NAME = WorkoutApp;
10891089
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
@@ -1120,7 +1120,7 @@
11201120
"$(inherited)",
11211121
"@executable_path/Frameworks",
11221122
);
1123-
MARKETING_VERSION = 3.5.3;
1123+
MARKETING_VERSION = 3.5.4;
11241124
PRODUCT_BUNDLE_IDENTIFIER = com.FGU.WorkOut;
11251125
PRODUCT_NAME = WorkoutApp;
11261126
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";

SwiftUI-WorkoutApp/Extensions/Binding+.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SwiftUI
22

33
extension Binding<Bool> {
4-
init<Wrapped>(bindingOptional: Binding<Wrapped?>) {
4+
init(bindingOptional: Binding<(some Any)?>) {
55
self.init(
66
get: { bindingOptional.wrappedValue != nil },
77
set: { newValue in

SwiftUI-WorkoutApp/SWModels/Sources/SWModels/EventForm.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct EventForm: Codable, Sendable, Equatable {
2828
self.photosCount = photosCount
2929
self.newMediaFiles = newMediaFiles
3030
}
31-
31+
3232
/// Инициализатор для создания формы на основе существующего мероприятия
3333
public init(_ event: EventResponse?) {
3434
let ground = event?.sportsGround
@@ -43,7 +43,7 @@ public struct EventForm: Codable, Sendable, Equatable {
4343
photosCount: event?.photos.count ?? 0
4444
)
4545
}
46-
46+
4747
public init(_ groundID: Int, _ groundName: String) {
4848
self.init(
4949
sportsGroundID: groundID,

SwiftUI-WorkoutApp/SWModels/Sources/SWModels/SportsGround.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public struct SportsGround: Codable, Identifiable, Hashable, Sendable {
2020
usersTrainHereCount ?? 0
2121
)
2222
}
23+
2324
public var commentsOptional: [CommentResponse]?
2425
public var usersTrainHere: [UserResponse]?
2526
public var trainHereOptional: Bool?
@@ -44,7 +45,7 @@ public struct SportsGround: Codable, Identifiable, Hashable, Sendable {
4445
public var authorName: String {
4546
author?.userName ?? ""
4647
}
47-
48+
4849
public var coordinate: CLLocationCoordinate2D {
4950
.init(
5051
latitude: .init(Double(latitude) ?? 0),
@@ -286,7 +287,7 @@ public final class GroundAnnotation: NSObject, MKAnnotation {
286287
public let coordinate: CLLocationCoordinate2D
287288
public let title: String?
288289
public let subtitle: String?
289-
290+
290291
private let regionRadius: CLLocationDistance = 1000
291292
public var region: MKCoordinateRegion {
292293
.init(
@@ -295,7 +296,7 @@ public final class GroundAnnotation: NSObject, MKAnnotation {
295296
longitudinalMeters: regionRadius
296297
)
297298
}
298-
299+
299300
public init(
300301
coordinate: CLLocationCoordinate2D,
301302
title: String?,

SwiftUI-WorkoutApp/SWNetworkClient/Sources/SWNetworkClient/SWClient+.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Foundation
2+
import OSLog
23
import SWModels
34

5+
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "SWClient")
6+
47
extension SWClient {
58
private var successCode: Int { 200 }
69
private var forceLogoutCode: Int { 401 }
@@ -64,14 +67,14 @@ extension SWClient {
6467
throw handleError(from: data, response: response)
6568
}
6669
#if DEBUG
67-
print("--- ✅ Получили JSON по запросу: ", (response?.url?.absoluteString) ?? "")
68-
print(data.prettyJson)
70+
let urlString = response?.url?.absoluteString ?? "unknown"
71+
logger.info("✅ Получили JSON по запросу: \(urlString)")
72+
logger.debug("\(data.prettyJson)")
6973
do {
7074
_ = try JSONDecoder().decode(type, from: data)
7175
} catch {
72-
print("--- ⛔️ Ошибка декодирования: \(error)")
76+
logger.error("⛔️ Ошибка декодирования: \(error)")
7377
}
74-
print("🏁")
7578
#endif
7679
return try JSONDecoder().decode(type, from: data)
7780
}
@@ -80,9 +83,8 @@ extension SWClient {
8083
func handle(_ response: URLResponse?) async throws -> Bool {
8184
let responseCode = (response as? HTTPURLResponse)?.statusCode
8285
#if DEBUG
83-
print("--- ✅ Получили статус по запросу: ", response?.url?.absoluteString ?? "")
84-
print(responseCode ?? 0)
85-
print("🏁")
86+
let urlString = response?.url?.absoluteString ?? "unknown"
87+
logger.info("✅ Получили статус \(responseCode ?? 0) по запросу: \(urlString)")
8688
#endif
8789
guard responseCode == successCode else {
8890
if canForceLogout, responseCode == forceLogoutCode {
@@ -106,9 +108,9 @@ extension SWClient {
106108
} else {
107109
"Ошибка!"
108110
}
109-
print("--- ⛔️ \(errorCodeMessage)\nJSON с ошибкой по запросу: ", response?.url?.absoluteString ?? "")
110-
print(data.prettyJson)
111-
print("🏁")
111+
let urlString = response?.url?.absoluteString ?? "unknown"
112+
logger.error("⛔️ \(errorCodeMessage)\nJSON с ошибкой по запросу: \(urlString)")
113+
logger.debug("\(data.prettyJson)")
112114
#endif
113115
if let errorInfo = try? JSONDecoder().decode(ErrorResponse.self, from: data) {
114116
return APIError(errorInfo, errorCode)

SwiftUI-WorkoutApp/Screens/Common/Incognito/IncognitoProfileView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SWModels
55
/// Заглушка для неавторизованного пользователя
66
struct IncognitoProfileView: View {
77
@State private var showAuthScreen = false
8-
8+
99
var body: some View {
1010
VStack(spacing: 16) {
1111
authInvitation
@@ -30,7 +30,7 @@ private extension IncognitoProfileView {
3030
.foregroundColor(.swMainText)
3131
.padding(.bottom, 6)
3232
}
33-
33+
3434
var goToLoginButton: some View {
3535
Button("Авторизация") {
3636
showAuthScreen = true

SwiftUI-WorkoutApp/Screens/Common/PhotoSection/PhotoSectionView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private extension PhotoSectionView {
6565
default: 3
6666
}
6767
}
68-
68+
6969
var gridView: some View {
7070
LazyVGrid(
7171
columns: .init(

SwiftUI-WorkoutApp/Screens/Common/SportsGroundLocation/MapSnapshotView.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import MapKit
2+
import OSLog
23
import SWDesignSystem
34
import SwiftUI
45
import SWModels
@@ -23,11 +24,11 @@ extension MapSnapshotView {
2324
struct MapModel: Equatable {
2425
let latitude: Double
2526
let longitude: Double
26-
27+
2728
var coordinate: CLLocationCoordinate2D {
2829
.init(latitude: latitude, longitude: longitude)
2930
}
30-
31+
3132
var isComplete: Bool {
3233
latitude != 0 && longitude != 0
3334
}
@@ -92,7 +93,8 @@ private extension MapSnapshotView {
9293
} else {
9394
snapshotImage = nil
9495
#if DEBUG
95-
print("--- Ошибка при создании снапшота карты: ", error?.localizedDescription ?? "")
96+
let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "MapSnapshotView")
97+
logger.error("Ошибка при создании снапшота карты: \(error)")
9698
#endif
9799
}
98100
}

SwiftUI-WorkoutApp/Screens/Events/Detail/EventDetailsView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private extension EventDetailsView {
288288
Label("Изменить", systemImage: Icons.Regular.pencil.rawValue)
289289
}
290290
}
291-
291+
292292
@ViewBuilder
293293
var lazyDestination: some View {
294294
if let eventToEdit {
@@ -340,7 +340,6 @@ private extension EventDetailsView {
340340
do {
341341
event = try await SWClient(with: defaults, needAuth: defaults.isAuthorized)
342342
.getEvent(by: event.id)
343-
print("EventForm: Загрузили event: \(event)")
344343
} catch {
345344
setupErrorAlert(ErrorFilter.message(from: error))
346345
}

SwiftUI-WorkoutApp/Screens/SportsGrounds/Detail/SportsGroundDetailView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private extension SportsGroundDetailView {
383383
? ground.authorID == defaults.mainUserInfo?.id
384384
: false
385385
}
386-
386+
387387
var canDeletePhoto: Bool {
388388
isGroundAuthor && ground.photos.count > 1
389389
}

0 commit comments

Comments
 (0)