Skip to content

Commit

Permalink
swiftlint chapter 1
Browse files Browse the repository at this point in the history
  • Loading branch information
icanzilb committed Feb 20, 2022
1 parent 84c4a0b commit bc6732a
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
9CEFEFDB22B98EB100B223AC /* Sources */,
9CEFEFDC22B98EB100B223AC /* Frameworks */,
9CEFEFDD22B98EB100B223AC /* Resources */,
9CA2B08027C2482800B569F8 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -167,6 +168,26 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
9CA2B08027C2482800B569F8 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "PATH=/opt/homebrew/bin:$PATH\nif [ -f ~/com.raywenderlich.swiftlint.yml ]; then\n if which swiftlint >/dev/null; then\n swiftlint --no-cache --config ~/com.raywenderlich.swiftlint.yml\n fi\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
9CEFEFDB22B98EB100B223AC /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import SwiftUI

@main
struct testappApp: App {
struct SavannaToursApp: App {
var body: some Scene {
WindowGroup {
ContentView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
import Foundation

func delay(seconds: TimeInterval, block: @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + seconds, execute: block)
DispatchQueue.main.asyncAfter(deadline: .now() + seconds, execute: block)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -12,32 +12,32 @@
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Copyright © 2019 Razeware LLC. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="0.0" y="626.5" width="375" height="20.5"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Copyright © 2022 Razeware LLC. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="0.0" y="855.5" width="414" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="SavannaTours" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<rect key="frame" x="0.0" y="202" width="375" height="43"/>
<rect key="frame" x="0.0" y="278" width="414" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" constant="20" symbolic="YES" id="SfN-ll-jLj"/>
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="SfN-ll-jLj"/>
<constraint firstAttribute="bottom" secondItem="obG-Y5-kRd" secondAttribute="bottom" constant="20" id="Y44-ml-fuU"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" constant="20" symbolic="YES" id="x7j-FC-K8j"/>
</constraints>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ import UIKit
import SwiftUI

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use a UIHostingController as window root view controller
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
}
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use a UIHostingController as window root view controller
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ struct MilestonesList: View {
var body: some View {
List((0...4), id: \.self) { num in
VStack(alignment: .leading) {
Text("Milestone #\(num+1)")
Text("Milestone #\(num + 1)")
.font(.title)
HStack(alignment: .lastTextBaseline) {
Text("Savanna National Park (\(num*12 + 5)km)")
Text("Savanna National Park (\(num * 12 + 5)km)")
.font(.subheadline)
Image(systemName: "pin")
Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ import Foundation
import SwiftUI

struct TourTitle: View {
let title: String
let caption: String
var body: some View {
VStack(alignment: .leading) {
Text(title)
.font(.largeTitle)
.fontWeight(.bold)
.shadow(radius: 5)
.foregroundColor(.white)
Text(caption)
.font(.caption)
.foregroundColor(.white)
}
}
let title: String
let caption: String

var body: some View {
VStack(alignment: .leading) {
Text(title)
.font(.largeTitle)
.fontWeight(.bold)
.shadow(radius: 5)
.foregroundColor(.white)

Text(caption)
.font(.caption)
.foregroundColor(.white)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,55 +28,57 @@

import SwiftUI

struct ContentView : View {
@State var zoomed = false

var body: some View {
VStack(spacing: 0) {
HeroImage(name: "hero")

ZStack {
HStack {
TourTitle(title: "Savanna Trek", caption: "15 mile drive followed by an hour long trek")
.offset(x: 0, y: -15)
.padding(.leading, 30)
.offset(x: self.zoomed ? 500 : 0, y: -15)
.animation(.default, value: self.zoomed)
struct ContentView: View {
@State var zoomed = false

Spacer()
}

GeometryReader() { geometry in
Image("thumb")
.clipShape(RoundedRectangle(cornerRadius: self.zoomed ? 40 : 500 ))
.overlay(
Circle()
.fill(self.zoomed ? Color.clear : Color(red: 1.0, green: 1.0, blue: 1.0, opacity: 0.4))
.scaleEffect(0.8)
)
.rotationEffect(self.zoomed ? Angle(degrees: 0) : Angle(degrees: 90))
.position(x: self.zoomed ? geometry.frame(in: .local).midX : 600,
y: 50)
.saturation(self.zoomed ? 1 : 0)
.scaleEffect(self.zoomed ? 1.33 : 0.33)
.shadow(radius: 10)
.animation(.spring(), value: self.zoomed)
.onTapGesture {
self.zoomed.toggle()
}
}
}
.background(Color(red: 0.1, green: 0.1, blue: 0.1))

MilestonesList()
}
}
var body: some View {
VStack(spacing: 0) {
HeroImage(name: "hero")

ZStack {
HStack {
TourTitle(title: "Savanna Trek", caption: "15 mile drive followed by an hour long trek")
.offset(x: 0, y: -15)
.padding(.leading, 30)
.offset(x: self.zoomed ? 500 : 0, y: -15)
.animation(.default, value: self.zoomed)

Spacer()
}

GeometryReader { geometry in
Image("thumb")
.clipShape(RoundedRectangle(cornerRadius: self.zoomed ? 40 : 500 ))
.overlay(
Circle()
.fill(self.zoomed ? Color.clear : Color(red: 1.0, green: 1.0, blue: 1.0, opacity: 0.4))
.scaleEffect(0.8)
)
.rotationEffect(self.zoomed ? Angle(degrees: 0) : Angle(degrees: 90))
.position(
x: self.zoomed ? geometry.frame(in: .local).midX : 600,
y: 50
)
.saturation(self.zoomed ? 1 : 0)
.scaleEffect(self.zoomed ? 1.33 : 0.33)
.shadow(radius: 10)
.animation(.spring(), value: self.zoomed)
.onTapGesture {
self.zoomed.toggle()
}
}
}
.background(Color(red: 0.1, green: 0.1, blue: 0.1))

MilestonesList()
}
}
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,52 @@
import SwiftUI

struct StarterView: View {
@State var currentOffset = 0
@State var color = Color.red
var body: some View {
ZStack {
Circle()
.scaleEffect(0.5)
.foregroundColor(colors[currentOffset])
@State var currentOffset = 0
@State var color = Color.red

var body: some View {
ZStack {
Circle()
.scaleEffect(0.5)
.foregroundColor(colors[currentOffset])
.animation(.default, value: currentOffset)
.offset(x: offsets[currentOffset].x,
y: offsets[currentOffset].y)
}
.onAppear {
for index in 1..<offsets.count {
delay(seconds: Double(index)) {
self.currentOffset = index
}
}
}
}
.offset(
x: offsets[currentOffset].x,
y: offsets[currentOffset].y
)
}
.onAppear {
for index in 1..<offsets.count {
delay(seconds: Double(index)) {
self.currentOffset = index
}
}
}
}
}

#if DEBUG
struct StarterView_Previews : PreviewProvider {
static var previews: some View {
StarterView()
}
struct StarterView_Previews: PreviewProvider {
static var previews: some View {
StarterView()
}
}
#endif

let offsets: [CGPoint] = [
CGPoint(x: 0, y: 0),
CGPoint(x: 100, y: 0),
CGPoint(x: 100, y: -100),
CGPoint(x: -100, y: -100),
CGPoint(x: -100, y: 0),
CGPoint(x: 0, y: 0),
CGPoint(x: 0, y: 0),
CGPoint(x: 100, y: 0),
CGPoint(x: 100, y: -100),
CGPoint(x: -100, y: -100),
CGPoint(x: -100, y: 0),
CGPoint(x: 0, y: 0)
]

let colors: [Color] = [
Color.green,
Color.blue,
Color.red,
Color.orange,
Color.yellow,
Color.green
Color.green,
Color.blue,
Color.red,
Color.orange,
Color.yellow,
Color.green
]

0 comments on commit bc6732a

Please sign in to comment.