Skip to content

Commit 2dca51a

Browse files
committed
Merge branch 'develop'
2 parents 6bda0fd + f656c49 commit 2dca51a

46 files changed

Lines changed: 4416 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/swift.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: "0 9 * * 1"
8+
9+
jobs:
10+
nextstep:
11+
runs-on: macos-latest
12+
steps:
13+
- name: Select latest available Xcode
14+
uses: maxim-lobanov/setup-xcode@v1.2.1
15+
with:
16+
xcode-version: 13
17+
- name: Checkout Repository
18+
uses: actions/checkout@v2
19+
- name: Build Swift Debug Package
20+
run: swift build -c debug
21+
- name: Build Swift Release Package
22+
run: swift build -c release

.gitignore

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Xcode
2+
#
3+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4+
5+
## Build generated
6+
build/
7+
DerivedData/
8+
9+
## Various settings
10+
*.pbxuser
11+
!default.pbxuser
12+
*.mode1v3
13+
!default.mode1v3
14+
*.mode2v3
15+
!default.mode2v3
16+
*.perspectivev3
17+
!default.perspectivev3
18+
xcuserdata/
19+
20+
## Other
21+
*.moved-aside
22+
*.xccheckout
23+
*.xcscmblueprint
24+
25+
## Obj-C/Swift specific
26+
*.hmap
27+
*.ipa
28+
*.dSYM.zip
29+
*.dSYM
30+
31+
## Playgrounds
32+
timeline.xctimeline
33+
playground.xcworkspace
34+
35+
# Swift Package Manager
36+
#
37+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
38+
# Packages/
39+
# Package.pins
40+
.build/
41+
42+
# CocoaPods
43+
#
44+
# We recommend against adding the Pods directory to your .gitignore. However
45+
# you should judge for yourself, the pros and cons are mentioned at:
46+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
47+
#
48+
# Pods/
49+
50+
# Carthage
51+
#
52+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
53+
# Carthage/Checkouts
54+
55+
Carthage/Build
56+
57+
# fastlane
58+
#
59+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
60+
# screenshots whenever they are needed.
61+
# For more information about the recommended setup visit:
62+
# https://docs.fastlane.tools/best-practices/source-control/#source-control
63+
64+
fastlane/report.xml
65+
fastlane/Preview.html
66+
fastlane/screenshots
67+
fastlane/test_output

Package.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// swift-tools-version:5.5
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "ViewController",
7+
platforms: [ .macOS(.v11), .iOS(.v15) ],
8+
products: [ .library(name: "ViewController", targets: [ "ViewController" ]) ],
9+
targets: [
10+
.target(name: "ViewController")
11+
]
12+
)

README.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# ViewController
2+
3+
ViewController's for SwiftUI.
4+
5+
WIP.
6+
7+
The core idea is that the `ViewController` is owning, or at least driving,
8+
the View(s). Not the other way around.
9+
10+
11+
## How to Use
12+
13+
More details will be posted but to get started.
14+
15+
### Step A: Setup Project and Root VC
16+
17+
- create a SwiftUI project in Xcode (iOS is tested better)
18+
- add the `ViewController` package,
19+
e.g. via `git@github.com:ZeeZide/ViewController.git`
20+
- create a new RootViewController, e.g. `HomePage.swift`:
21+
```swift
22+
import ViewController
23+
24+
class HomePage: ViewController {
25+
26+
struct ContentView: View {
27+
28+
var body: some View {
29+
VStack {
30+
Text("Welcome to MWC!")
31+
.font(.title)
32+
.padding()
33+
34+
Spacer()
35+
}
36+
}
37+
}
38+
}
39+
```
40+
- Instantiate that in the scene view, the `ContentView.swift`
41+
generated by Xcode:
42+
```swift
43+
import ViewController
44+
45+
struct ContentView: View {
46+
var body: some View {
47+
MainViewController(HomePage())
48+
}
49+
}
50+
```
51+
- Compile and Run, should show the HomePage
52+
53+
### Step B: Add a presented VC and navigate to it
54+
55+
- create a new ViewController, e.g. `Settings.swift`:
56+
```swift
57+
import ViewController
58+
59+
class Settings: ViewController {
60+
61+
struct ContentView: View {
62+
63+
var body: some View {
64+
VStack {
65+
Text("Welcome to Settings!")
66+
.font(.title)
67+
.padding()
68+
69+
Spacer()
70+
}
71+
}
72+
}
73+
}
74+
```
75+
- Add an action to present the `Settings` from the `HomePage`:
76+
```swift
77+
import ViewController
78+
79+
class HomePage: ViewController {
80+
81+
func configureApp() {
82+
show(Settings()) // or `present(Settings())`
83+
}
84+
85+
struct ContentView: View {
86+
87+
@EnvironmentObject private var viewController : HomePage
88+
89+
var body: some View {
90+
VStack {
91+
Text("Welcome to MWC!")
92+
.font(.title)
93+
.padding()
94+
95+
Divider()
96+
97+
Button(action: viewController.configureApp) {
98+
Label("Configure", systemImage: "gear")
99+
}
100+
101+
Spacer()
102+
}
103+
}
104+
}
105+
}
106+
```
107+
108+
Pressing the button should show the settings in a sheet.
109+
110+
111+
### Step C: Add a NavigationController for Navigation :-)
112+
113+
- Wrap the HomePage in a `NavigationController`, in the scene view:
114+
```swift
115+
import ViewController
116+
117+
struct ContentView: View {
118+
var body: some View {
119+
MainViewController(NavigationController(rootViewController: HomePage()))
120+
}
121+
}
122+
```
123+
124+
Note pressing the button does a navigation. Things like this should also
125+
work:
126+
```swift
127+
func presentInSheet() {
128+
let vc = SettingsPage()
129+
vc.modalPresentationStyle = .sheet
130+
present(vc)
131+
}
132+
```
133+
134+
135+
### Adding a `PushLink`
136+
137+
The presentations so far make use of a hidden link. To explicitly
138+
inline a `NavigationLink`, use `PushLink`, which wraps that.
139+
140+
- Add a `PushLink` (until I get an `NavigationLink` init extension working)
141+
to present the `Settings` from the `HomePage`:
142+
```swift
143+
import ViewController
144+
145+
class HomePage: ViewController {
146+
147+
struct ContentView: View {
148+
149+
var body: some View {
150+
VStack {
151+
Text("Welcome to MWC!")
152+
.font(.title)
153+
.padding()
154+
155+
Divider()
156+
157+
PushLink("Open Settings", to: Settings())
158+
159+
Spacer()
160+
}
161+
}
162+
}
163+
}
164+
```
165+
166+
167+
### Who
168+
169+
ViewController is brought to you by [ZeeZide](https://zeezide.de).
170+
We like feedback, GitHub stars, cool contract work,
171+
presumably any form of praise you can think of.
172+
173+
**Want to support my work**?
174+
Buy an app:
175+
[Past for iChat](https://apps.apple.com/us/app/past-for-ichat/id1554897185),
176+
[SVG Shaper](https://apps.apple.com/us/app/svg-shaper-for-swiftui/id1566140414),
177+
[Shrugs](https://shrugs.app/),
178+
[HMScriptEditor](https://apps.apple.com/us/app/hmscripteditor/id1483239744).
179+
You don't have to use it! 😀

0 commit comments

Comments
 (0)