Skip to content

Commit

Permalink
Implement SwiftLint and SwiftGen
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Mifsud committed Sep 14, 2021
1 parent 6255398 commit 1e99478
Show file tree
Hide file tree
Showing 62 changed files with 2,586 additions and 2,052 deletions.
4 changes: 4 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line_length: 120

excluded:
- TendrTests (iOS)
2 changes: 2 additions & 0 deletions Mintfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
realm/swiftlint
SwiftGen/SwiftGen
66 changes: 33 additions & 33 deletions Shared/AppSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ import SwiftUI

/// AppSection enum to represent each of the tabs in the TabBar
enum AppSection: CustomStringConvertible {
case history
case home
case settings
/// Text description for the tab
var description: String {
switch self {
case .history:
return NSLocalizedString("History", comment: "History Tab")
case .home:
return NSLocalizedString("Home", comment: "Home Tab")
case .settings:
return NSLocalizedString("Settings", comment: "Settings Tab")
}
}
/// Image for the tab
var icon: Image {
switch self {
case .history:
return Image(systemName: "clock")
case .home:
return Image(systemName: "rectangle.stack.person.crop")
case .settings:
return Image(systemName: "gearshape")
}
}
/// Tab item for the given tab
@ViewBuilder var tabView: some View {
self.icon
Text(String(describing: self))
}
case history
case home
case settings

/// Text description for the tab
var description: String {
switch self {
case .history:
return L10n.TabBar.Tab.history
case .home:
return L10n.TabBar.Tab.home
case .settings:
return L10n.TabBar.Tab.settings
}
}

/// Image for the tab
var icon: Image {
switch self {
case .history:
return Image(systemName: "clock")
case .home:
return Image(systemName: "rectangle.stack.person.crop")
case .settings:
return Image(systemName: "gearshape")
}
}

/// Tab item for the given tab
@ViewBuilder var tabView: some View {
self.icon
Text(String(describing: self))
}
}
92 changes: 46 additions & 46 deletions Shared/Authentication/AuthManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,53 @@ import Combine
import os

class AuthManager: ObservableObject {
private var defaults = UserDefaults.standard
private var logger: Logger = Logger(subsystem: bundleId, category: "Authentication Errors")
var isAuthenticated: Bool {
authToken != nil
}
/// The persisted auth token from the Tendr Api
@Published var authToken: String? {
willSet {
defaults.set(newValue, forKey: AppStorageConstants.apiAuthToken)
}
}
/// The persisted Sign in with apple user credential.
@Published var appleUserId: String? {
willSet {
defaults.set(newValue, forKey: AppStorageConstants.appleUserId)
}
}
init() {
withAnimation {
authToken = defaults.string(forKey: AppStorageConstants.apiAuthToken)
appleUserId = defaults.string(forKey: AppStorageConstants.appleUserId)
}
}
/// Submit an Auth Request using a network client.
/// - Parameter client: `NetworkClient` to use for the request.
func fetchAuthToken(with client: NetworkClient<AuthRequest, Empty>) {
client.load()
}
/// Clear the users persisted session.
func logout() {
withAnimation {
authToken = nil
appleUserId = nil
}
}
private var defaults = UserDefaults.standard
private var logger: Logger = Logger(subsystem: bundleId, category: "Authentication Errors")

var isAuthenticated: Bool {
authToken != nil
}

/// The persisted auth token from the Tendr Api
@Published var authToken: String? {
willSet {
defaults.set(newValue, forKey: AppStorageConstants.apiAuthToken)
}
}

/// The persisted Sign in with apple user credential.
@Published var appleUserId: String? {
willSet {
defaults.set(newValue, forKey: AppStorageConstants.appleUserId)
}
}

init() {
withAnimation {
authToken = defaults.string(forKey: AppStorageConstants.apiAuthToken)
appleUserId = defaults.string(forKey: AppStorageConstants.appleUserId)
}
}

/// Submit an Auth Request using a network client.
/// - Parameter client: `NetworkClient` to use for the request.
func fetchAuthToken(with client: NetworkClient<AuthRequest, Empty>) {
client.load()
}

/// Clear the users persisted session.
func logout() {
withAnimation {
authToken = nil
appleUserId = nil
}
}
}

class MockAuthManager: AuthManager {
override func fetchAuthToken(with client: NetworkClient<AuthRequest, Empty>) {
withAnimation {
self.authToken = self.appleUserId
}
}
override func fetchAuthToken(with client: NetworkClient<AuthRequest, Empty>) {
withAnimation {
self.authToken = self.appleUserId
}
}
}
42 changes: 42 additions & 0 deletions Shared/Colors.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"colors" : [
{
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "contrast",
"value" : "high"
}
],
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
},
{
"appearance" : "contrast",
"value" : "high"
}
],
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions Shared/Constants/AppStorageConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

enum AppStorageConstants {
static let apiAuthToken = "com.codingcouch.tendr.authtoken"
static let appleUserId = "com.codingcouch.tendr.appleuserid"
static let apiAuthToken = "com.codingcouch.tendr.authtoken"
static let appleUserId = "com.codingcouch.tendr.appleuserid"
static let nsfwEnabled = "com.codingcouch.tendr.nsfw"
}
22 changes: 8 additions & 14 deletions Shared/Error/AlertContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ import Foundation
import SwiftUI

struct AlertContent: Identifiable {
private(set) var id: UUID = UUID()
var title: String
var message: String?

var standardMessage: Text? {
guard let message = message else { return nil }

return Text("""
Please send us a screenshot of this alert!
Time Occured: \(Date())
Error Details:
\(message)
""")
}
private(set) var id: UUID = UUID()
var title: String
var message: String?

var standardMessage: Text? {
guard let message = message else { return nil }
return Text(L10n.Alerts.Error.standard("\(Date())", "\(message)"))
}
}
18 changes: 9 additions & 9 deletions Shared/Extension/CGFloat+Measurements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import Foundation
import CoreGraphics

extension CGFloat {
// Margins
// Margins
static let largeMargin: CGFloat = 32
static let margin: CGFloat = 16
static let smallMargin: CGFloat = 8
// Corner Radii
static let cornerRadius: CGFloat = 16
static let smallRadius: CGFloat = 8
static let smallerRadius: CGFloat = 6
static let smallestRadius: CGFloat = 4
static let margin: CGFloat = 16
static let smallMargin: CGFloat = 8

// Corner Radii
static let cornerRadius: CGFloat = 16
static let smallRadius: CGFloat = 8
static let smallerRadius: CGFloat = 6
static let smallestRadius: CGFloat = 4
}
4 changes: 1 addition & 3 deletions Shared/Extension/View+Hidden.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

extension View {

/// Hide or show the view based on a boolean value.
///
/// Example for visibility:
Expand Down Expand Up @@ -36,5 +36,3 @@ extension View {
}
}
}


Loading

0 comments on commit 1e99478

Please sign in to comment.