Skip to content

Commit

Permalink
Format swift (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski authored Nov 11, 2022
1 parent c8f0b60 commit cd0da54
Show file tree
Hide file tree
Showing 445 changed files with 25,384 additions and 16,123 deletions.
58 changes: 58 additions & 0 deletions .swift-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentation" : {
"spaces" : 4
},
"indentConditionalCompilationBlocks" : true,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : true,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 80,
"maximumBlankLines" : 1,
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : true,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : true,
"NeverUseForceTry" : true,
"NeverUseImplicitlyUnwrappedOptionals" : true,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : true,
"UseLetInEveryBoundCaseVariable" : true,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"tabWidth" : 8,
"version" : 1
}


44 changes: 25 additions & 19 deletions Airship Sample/Airship Sample/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
/* Copyright Urban Airship and Contributors */

import UIKit
import AirshipCore
import AirshipMessageCenter
import AirshipPreferenceCenter
import UIKit

#if canImport(ActivityKit)
import ActivityKit
import ActivityKit
#endif

class AppDelegate: UIResponder, UIApplicationDelegate, DeepLinkDelegate, MessageCenterDisplayDelegate, PreferenceCenterOpenDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
class AppDelegate: UIResponder, UIApplicationDelegate, DeepLinkDelegate,
MessageCenterDisplayDelegate, PreferenceCenterOpenDelegate
{

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication
.LaunchOptionsKey: Any]? = nil
) -> Bool {

let config = Config.default()
config.productionLogLevel = .trace
Expand All @@ -24,8 +29,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, DeepLinkDelegate, Message
Airship.push.notificationOptions = [.alert, .badge, .sound, .carPlay]
Airship.push.defaultPresentationOptions = [.sound, .banner, .list]



Airship.shared.deepLinkDelegate = self
MessageCenter.shared.displayDelegate = self
PreferenceCenter.shared.openDelegate = self
Expand All @@ -39,30 +42,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate, DeepLinkDelegate, Message
Airship.push.resetBadge()
}

#if canImport(ActivityKit)
if #available(iOS 16.1, *) {
Task {
await Airship.channel.restoreLiveActivityTracking { restorer in
await restorer.restore(forType: Activity<DeliveryAttributes>.self)
#if canImport(ActivityKit)
if #available(iOS 16.1, *) {
Task {
await Airship.channel.restoreLiveActivityTracking {
restorer in
await restorer.restore(
forType: Activity<DeliveryAttributes>.self
)
}
}
}
}
#endif

#endif

return true
}


func showInvalidDeepLinkAlert(_ url: URL) {
AppState.shared.toastMessage = Toast.Message(
text: "App does not know how to handle deepLink \(url)",
duration: 2.0
)
}

func receivedDeepLink(_ deepLink: URL,
completionHandler: @escaping () -> Void) {
func receivedDeepLink(
_ deepLink: URL,
completionHandler: @escaping () -> Void
) {
DispatchQueue.main.async {
guard deepLink.host?.lowercased() == "deeplink" else {
self.showInvalidDeepLinkAlert(deepLink)
Expand All @@ -71,7 +77,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, DeepLinkDelegate, Message
}

let components = deepLink.path.lowercased().split(separator: "/")
switch(components.first) {
switch components.first {
case "settings":
AppState.shared.homeDestination = .settings
AppState.shared.selectedTab = .home
Expand Down
10 changes: 4 additions & 6 deletions Airship Sample/Airship Sample/AppState.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Copyright Urban Airship and Contributors */

import SwiftUI
import Combine
import AirshipCore
import AirshipMessageCenter
import Combine
import SwiftUI

class AppState: ObservableObject {
static let shared = AppState()
Expand All @@ -17,15 +17,15 @@ class AppState: ObservableObject {
var homeDestination: HomeDestination? = nil

@Published
var unreadCount = 0;
var unreadCount = 0

@Published
var toastMessage: Toast.Message?

private var subscriptions = Set<AnyCancellable>()

init() {
if (Airship.isFlying) {
if Airship.isFlying {
MessageCenter.shared.inbox.unreadCountPublisher
.receive(on: RunLoop.main)
.sink { unreadCount in
Expand All @@ -48,5 +48,3 @@ enum HomeDestination: Hashable {
case namedUser
case liveactivities
}


6 changes: 2 additions & 4 deletions Airship Sample/Airship Sample/AppView.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Copyright Urban Airship and Contributors */

import SwiftUI
import AirshipCore
import AirshipPreferenceCenter
import AirshipMessageCenter
import AirshipPreferenceCenter
import SwiftUI

struct AppView: View {

Expand Down Expand Up @@ -66,7 +66,6 @@ struct AppView: View {
}
}


extension View {
@ViewBuilder
func badgeCompat(_ badge: Int) -> some View {
Expand All @@ -83,4 +82,3 @@ struct AppView_Previews: PreviewProvider {
AppView()
}
}

83 changes: 41 additions & 42 deletions Airship Sample/Airship Sample/HomeView.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
/* Copyright Urban Airship and Contributors */

import AirshipCore
import SwiftUI
import Combine
import SwiftUI

#if canImport(AirshipDebug)
import AirshipDebug
import AirshipDebug
#endif

struct HomeView: View {

@StateObject
private var viewModel: ViewModel = ViewModel()

@Environment(\.verticalSizeClass)
private var verticalSizeClass

@EnvironmentObject
private var appState: AppState

@ViewBuilder
private func makeQuickSettingItem(title: String, value: String) -> some View {
private func makeQuickSettingItem(title: String, value: String) -> some View
{
VStack(alignment: .leading) {
Text(title)
.foregroundColor(.accentColor)
Expand Down Expand Up @@ -66,23 +67,22 @@ struct HomeView: View {
)
}


Divider()

#if canImport(ActivityKit)
if #available(iOS 16.1, *) {
NavigationLink(
destination: LiveActivityManagementView(),
tag: HomeDestination.liveactivities,
selection: self.$appState.homeDestination
) {
Text("Live Activities!")
.foregroundColor(.accentColor)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
#if canImport(ActivityKit)
if #available(iOS 16.1, *) {
NavigationLink(
destination: LiveActivityManagementView(),
tag: HomeDestination.liveactivities,
selection: self.$appState.homeDestination
) {
Text("Live Activities!")
.foregroundColor(.accentColor)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
#endif
#endif
}
}
}
Expand All @@ -95,7 +95,7 @@ struct HomeView: View {
.padding(.horizontal, 16)
.padding(.vertical, 8)
}

@ViewBuilder
func makeEnablePushButton() -> some View {
// MARK: Push/Bleat Button
Expand All @@ -105,8 +105,9 @@ struct HomeView: View {
.strokeBorder(Color.accentColor, lineWidth: 2.0)
.frame(height: 40, alignment: .center)
.padding()

let title = self.viewModel.pushEnabled ? "Disable Push" : "Enable Push"

let title =
self.viewModel.pushEnabled ? "Disable Push" : "Enable Push"
Text(title)
.fontWeight(.bold)
.foregroundColor(.primary)
Expand Down Expand Up @@ -145,7 +146,7 @@ struct HomeView: View {
var body: some View {
NavigationView {
ZStack {
if (self.verticalSizeClass == .compact) {
if self.verticalSizeClass == .compact {
makeCompactContent()
} else {
makeContent()
Expand All @@ -162,27 +163,29 @@ struct HomeView: View {
@ViewBuilder
private func makeSettingLink() -> some View {
#if canImport(AirshipDebug)
NavigationLink(
destination: AirshipDebugView(),
tag: HomeDestination.settings,
selection: self.$appState.homeDestination
) {
Image(systemName: "gear")
.resizable()
.scaledToFit()
.foregroundColor(.accentColor)
.padding(10)
.frame(width: 44, height: 44)
}
NavigationLink(
destination: AirshipDebugView(),
tag: HomeDestination.settings,
selection: self.$appState.homeDestination
) {
Image(systemName: "gear")
.resizable()
.scaledToFit()
.foregroundColor(.accentColor)
.padding(10)
.frame(width: 44, height: 44)
}
#endif
}


class ViewModel : ObservableObject {
class ViewModel: ObservableObject {
@Published
var pushEnabled: Bool = Airship.push.userPushNotificationsEnabled && Airship.shared.privacyManager.isEnabled(.push) {
var pushEnabled: Bool =
Airship.push.userPushNotificationsEnabled
&& Airship.shared.privacyManager.isEnabled(.push)
{
didSet {
if (pushEnabled) {
if pushEnabled {
Airship.shared.privacyManager.enableFeatures(.push)
Airship.push.userPushNotificationsEnabled = true
} else {
Expand All @@ -199,8 +202,6 @@ struct HomeView: View {

private var subscriptions = Set<AnyCancellable>()



init() {
NotificationCenter.default
.publisher(for: Channel.channelCreatedEvent)
Expand All @@ -210,7 +211,6 @@ struct HomeView: View {
}
.store(in: &self.subscriptions)


NotificationCenter.default
.publisher(for: Contact.contactChangedEvent)
.receive(on: RunLoop.main)
Expand All @@ -226,4 +226,3 @@ struct HomeView: View {

}
}

Loading

0 comments on commit cd0da54

Please sign in to comment.