-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0980f93
commit 1b8744b
Showing
36 changed files
with
495 additions
and
11 deletions.
There are no files selected for viewing
Binary file added
BIN
+48.6 KB
.../NetworkReachability/NetworkReachability.docc/Images/Tutorials/PreviewColor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+275 KB
...NetworkReachability/NetworkReachability.docc/Images/Tutorials/PreviewSymbol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.4 KB
...achability/NetworkReachability.docc/Images/Tutorials/PreviewSymbolFormatted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+717 KB
...NetworkReachability/NetworkReachability.docc/Images/Tutorials/SFSymbolsIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+27.6 KB
...s/NetworkReachability/NetworkReachability.docc/Images/Tutorials/SampleIcon2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+54.2 KB
...s/NetworkReachability/NetworkReachability.docc/Images/Tutorials/SwiftUIIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+558 KB
.../NetworkReachability/NetworkReachability.docc/Images/Tutorials/XcodeNewFile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added
BIN
+551 KB
...kReachability/NetworkReachability.docc/Images/Tutorials/XcodeSidebarSwiftUI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-241 KB
...Reachability/NetworkReachability.docc/Images/Tutorials/XcodeTemplateOptions.png
Binary file not shown.
Binary file added
BIN
+201 KB
...ty/NetworkReachability.docc/Images/Tutorials/XcodeTemplateOptionsStoryboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+249 KB
...ility/NetworkReachability.docc/Images/Tutorials/XcodeTemplateOptionsSwiftUI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+500 KB
Sources/NetworkReachability/NetworkReachability.docc/Projects/ProjectIntegrate-SwiftUI.zip
Binary file not shown.
File renamed without changes.
Binary file added
BIN
+247 KB
Sources/NetworkReachability/NetworkReachability.docc/Projects/ProjectSetup-SwiftUI.zip
Binary file not shown.
File renamed without changes.
Binary file added
BIN
+507 KB
Sources/NetworkReachability/NetworkReachability.docc/Projects/ProjectUI-SwiftUI.zip
Binary file not shown.
File renamed without changes.
44 changes: 44 additions & 0 deletions
44
Sources/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/ComputeColor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
|
||
@ObservedObject | ||
var reachabilityManager: ReachabilityManager | ||
|
||
var body: some View { | ||
Text("Hello, world!") | ||
.padding() | ||
} | ||
|
||
private var symbolName: String { | ||
switch reachabilityManager.reachability { | ||
case .wifi: | ||
return "wifi.circle.fill" | ||
case .ethernet: | ||
return "cable.connector" | ||
case .unknown: | ||
return "questionmark.circle.fill" | ||
case .cellular: | ||
return "antenna.radiowaves.left.and.right.circle.fill" | ||
case .disconnected: | ||
return "xmark.circle.fill" | ||
} | ||
} | ||
|
||
private var backgroundColor: Color { | ||
switch reachabilityManager.reachability { | ||
case .disconnected: | ||
return .red | ||
case .unknown: | ||
return .yellow | ||
case .wifi, .ethernet, .cellular: | ||
return .green | ||
} | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView(reachabilityManager: .init()) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Sources/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/ComputeSymbol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
|
||
@ObservedObject | ||
var reachabilityManager: ReachabilityManager | ||
|
||
var body: some View { | ||
Text("Hello, world!") | ||
.padding() | ||
} | ||
|
||
private var symbolName: String { | ||
switch reachabilityManager.reachability { | ||
case .wifi: | ||
return "wifi.circle.fill" | ||
case .ethernet: | ||
return "cable.connector" | ||
case .unknown: | ||
return "questionmark.circle.fill" | ||
case .cellular: | ||
return "antenna.radiowaves.left.and.right.circle.fill" | ||
case .disconnected: | ||
return "xmark.circle.fill" | ||
} | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView(reachabilityManager: .init()) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Sources/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/ContentView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
var body: some View { | ||
Text("Hello, world!") | ||
.padding() | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Sources/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/CreateStatus.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
final class ReachabilityManager { | ||
|
||
enum Status { | ||
case ethernet | ||
case wifi | ||
case cellular | ||
case unknown | ||
case disconnected | ||
} | ||
|
||
var reachability: Status = .disconnected | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
Sources/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/FormatSymbol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
|
||
@ObservedObject | ||
var reachabilityManager: ReachabilityManager | ||
|
||
var body: some View { | ||
Image(systemName: symbolName) | ||
.resizable() | ||
.frame(width: 60, height: 60) | ||
} | ||
|
||
private var symbolName: String { | ||
switch reachabilityManager.reachability { | ||
case .wifi: | ||
return "wifi.circle.fill" | ||
case .ethernet: | ||
return "cable.connector" | ||
case .unknown: | ||
return "questionmark.circle.fill" | ||
case .cellular: | ||
return "antenna.radiowaves.left.and.right.circle.fill" | ||
case .disconnected: | ||
return "xmark.circle.fill" | ||
} | ||
} | ||
|
||
private var backgroundColor: Color { | ||
switch reachabilityManager.reachability { | ||
case .disconnected: | ||
return .red | ||
case .unknown: | ||
return .yellow | ||
case .wifi, .ethernet, .cellular: | ||
return .green | ||
} | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView(reachabilityManager: .init()) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...es/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/ImplementManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Combine | ||
import Network | ||
import NetworkReachability | ||
|
||
final class ReachabilityManager: ObservableObject { | ||
|
||
init() { | ||
setUp() | ||
} | ||
|
||
enum Status { | ||
case ethernet | ||
case wifi | ||
case cellular | ||
case unknown | ||
case disconnected | ||
} | ||
|
||
@Published | ||
var reachability: Status = .disconnected | ||
|
||
private var monitor: NetworkMonitor! | ||
|
||
private func setUp() { | ||
monitor = .init() { [weak self] _, networkPath in | ||
guard let self = self else { return } | ||
if networkPath.usesInterfaceType(.wiredEthernet) { | ||
self.reachability = .ethernet | ||
} else if networkPath.usesInterfaceType(.wifi) { | ||
self.reachability = .wifi | ||
} else if networkPath.usesInterfaceType(.cellular) { | ||
self.reachability = .cellular | ||
} else if networkPath.status == .satisfied { | ||
self.reachability = .unknown | ||
} else { | ||
self.reachability = .disconnected | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...etworkReachability/NetworkReachability.docc/Snippets/Tutorials/MakeObservableObject.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Combine | ||
|
||
final class ReachabilityManager: ObservableObject { | ||
|
||
enum Status { | ||
case ethernet | ||
case wifi | ||
case cellular | ||
case unknown | ||
case disconnected | ||
} | ||
|
||
@Published | ||
var reachability: Status = .disconnected | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ces/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/ReachabilityApp.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import SwiftUI | ||
|
||
@main | ||
struct ReachabilityApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView(reachabilityManager: ReachabilityManager()) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...orkReachability/NetworkReachability.docc/Snippets/Tutorials/ReachabilityAppTemplate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import SwiftUI | ||
|
||
@main | ||
struct ReachabilityApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Sources/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/UseColor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
|
||
@ObservedObject | ||
var reachabilityManager: ReachabilityManager | ||
|
||
var body: some View { | ||
ZStack { | ||
Image(systemName: symbolName) | ||
.resizable() | ||
.frame(width: 60, height: 60) | ||
} | ||
.frame(maxWidth: .infinity, | ||
maxHeight: .infinity) | ||
.background(backgroundColor) | ||
} | ||
|
||
private var symbolName: String { | ||
switch reachabilityManager.reachability { | ||
case .wifi: | ||
return "wifi.circle.fill" | ||
case .ethernet: | ||
return "cable.connector" | ||
case .unknown: | ||
return "questionmark.circle.fill" | ||
case .cellular: | ||
return "antenna.radiowaves.left.and.right.circle.fill" | ||
case .disconnected: | ||
return "xmark.circle.fill" | ||
} | ||
} | ||
|
||
private var backgroundColor: Color { | ||
switch reachabilityManager.reachability { | ||
case .disconnected: | ||
return .red | ||
case .unknown: | ||
return .yellow | ||
case .wifi, .ethernet, .cellular: | ||
return .green | ||
} | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView(reachabilityManager: .init()) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Sources/NetworkReachability/NetworkReachability.docc/Snippets/Tutorials/UseSymbol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
|
||
@ObservedObject | ||
var reachabilityManager: ReachabilityManager | ||
|
||
var body: some View { | ||
Image(systemName: symbolName) | ||
} | ||
|
||
private var symbolName: String { | ||
switch reachabilityManager.reachability { | ||
case .wifi: | ||
return "wifi.circle.fill" | ||
case .ethernet: | ||
return "cable.connector" | ||
case .unknown: | ||
return "questionmark.circle.fill" | ||
case .cellular: | ||
return "antenna.radiowaves.left.and.right.circle.fill" | ||
case .disconnected: | ||
return "xmark.circle.fill" | ||
} | ||
} | ||
|
||
private var backgroundColor: Color { | ||
switch reachabilityManager.reachability { | ||
case .disconnected: | ||
return .red | ||
case .unknown: | ||
return .yellow | ||
case .wifi, .ethernet, .cellular: | ||
return .green | ||
} | ||
} | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView(reachabilityManager: .init()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...achability.docc/Tutorials/SampleProject-SwiftUI/SampleProjectIntegration-SwiftUI.tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@Tutorial(time: 5, projectFiles: "ProjectIntegrate-SwiftUI.zip") { | ||
@XcodeRequirement(title: "Xcode 13", destination: "https://developer.apple.com/download/") | ||
@Intro(title: "Implementing Reachability") { | ||
This tutorial guides you through the process of consuming reachability data in your application. | ||
} | ||
|
||
@Section(title: "Integrate Reachability") { | ||
@ContentAndMedia { | ||
Create an `ObservableObject` for use with SwiftUI using NetworkReachability and callback closures. | ||
@Image(source: "SampleIcon2.png", alt: "Sample App Icon") | ||
} | ||
|
||
@Steps { | ||
@Step { | ||
Choose File > New > File, select iOS as the platform, select the “Swift File” template, and click Next. Name the new file "ReachabilityManager.swift" and click Create. | ||
|
||
@Image(source: "XcodeNewFile", alt: "New File Chooser") | ||
} | ||
|
||
@Step { | ||
Create a new class, and create an enumeration representing the various reachability options within your new class. | ||
@Code(name: "ReachabilityManager.swift", file: "CreateStatus.swift") | ||
} | ||
|
||
@Step { | ||
Make your class an `ObservableObject` and annotate the instance variable with the `@Published` property wrapper. | ||
@Code(name: "ReachabilityManager.swift", file: "MakeObservableObject.swift") | ||
} | ||
|
||
@Step { | ||
Create a `NetworkMonitor` class and use the callback API to recieve updates from the monitor. | ||
@Code(name: "ReachabilityManager.swift", file: "ImplementManager.swift") | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.