-
Notifications
You must be signed in to change notification settings - Fork 299
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
10a13fa
commit 26c8d0c
Showing
792 changed files
with
79,388 additions
and
0 deletions.
There are no files selected for viewing
614 changes: 614 additions & 0 deletions
614
...-macro-case-paths-pt2/CasePathExplorations/CasePathExplorations.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...hExplorations/CasePathExplorations.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
.../CasePathExplorations.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
11 changes: 11 additions & 0 deletions
11
...ePathExplorations/CasePathExplorations/Assets.xcassets/AccentColor.colorset/Contents.json
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,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...asePathExplorations/CasePathExplorations/Assets.xcassets/AppIcon.appiconset/Contents.json
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 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ro-case-paths-pt2/CasePathExplorations/CasePathExplorations/Assets.xcassets/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
...macro-case-paths-pt2/CasePathExplorations/CasePathExplorations/CasePathExplorations.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,134 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
struct User { | ||
let id: UUID | ||
var name: String | ||
} | ||
|
||
let kp1 = \User.id | ||
let kp2 = \User.name | ||
|
||
func f() { | ||
var user = User(id: UUID(), name: "Blob") | ||
let id = user[keyPath: \User.id] | ||
user[keyPath: \User.name] = "Blob, Jr" | ||
|
||
user.id | ||
user.name = "Blob, Jr" | ||
|
||
let users = [ | ||
User(id: UUID(), name: "Blob"), | ||
User(id: UUID(), name: "Blob Jr."), | ||
User(id: UUID(), name: "Blob Sr."), | ||
] | ||
// let names = users.map { $0.name } | ||
let names = users.map(\.name) | ||
|
||
let loadings = [Loading.inProgress, Loading.loaded("Blob")] | ||
let loadeds = loadings.compactMap(\.loaded) | ||
} | ||
|
||
extension Binding { | ||
subscript<Member>( | ||
dynamicMember keyPath: WritableKeyPath<Value, Member> | ||
) -> Binding<Member> { | ||
Binding<Member>( | ||
get: { self.wrappedValue[keyPath: keyPath] }, | ||
set: { self.wrappedValue[keyPath: keyPath] = $0 } | ||
) | ||
} | ||
} | ||
|
||
struct SomeView: View { | ||
@Binding var user: User | ||
|
||
var body: some View { | ||
let nameBinding = $user.name | ||
EmptyView() | ||
.environment(\.colorScheme, .dark) | ||
} | ||
} | ||
|
||
func g() { | ||
var user = User(id: UUID(), name: "Blob, Sr") | ||
withUnsafeMutablePointer(to: &user) { userPtr in | ||
let namePtr = userPtr.pointer(to: \.name) | ||
let idPtr = userPtr.pointer(to: \.id) | ||
} | ||
} | ||
|
||
let getUserID: (User) -> UUID = { $0.id } | ||
let getUserName: (User) -> String = { $0.name } | ||
let setUserName: (inout User, String) -> Void = { $0.name = $1 } | ||
|
||
struct GetterAndSetter<Root, Value> { | ||
var get: (Root) -> Value | ||
var set: (inout Root, Value) -> Void | ||
} | ||
|
||
extension GetterAndSetter where Root == User, Value == String { | ||
static var name: Self { | ||
Self(get: { $0.name }, set: { $0.name = $1 }) | ||
} | ||
} | ||
|
||
enum Loading { | ||
case inProgress | ||
case loaded(String) | ||
} | ||
|
||
let extractLoaded: (Loading) -> String? = { | ||
guard case let .loaded(value) = $0 | ||
else { return nil } | ||
return value | ||
} | ||
let embedLoaded: (String) -> Loading = Loading.loaded | ||
|
||
//struct CasePath<Root, Value> { | ||
// let extract: (Root) -> Value? | ||
// let embed: (Value) -> Root | ||
//} | ||
|
||
//\Loading.loaded // WritableKeyPath<Loading, String?> | ||
|
||
func h() { | ||
var value = Loading.inProgress | ||
// value[keyPath: \.loaded] // nil | ||
// | ||
// value[keyPath: \.loaded] = 1 // ??? | ||
// value[keyPath: \.loaded] = nil // ??? | ||
} | ||
|
||
import CasePaths | ||
|
||
let loadedCasePath = /Loading.loaded | ||
let nameKeyPath = \User.name | ||
|
||
func j() throws { | ||
var value = Loading.loaded("Hello") | ||
(/Loading.loaded).extract(from: value) // "Hello" | ||
(/Loading.inProgress).extract(from: value) // nil | ||
(/Loading.loaded).embed("Hello") | ||
|
||
//user[keyPath: \.name] = "Blob" | ||
|
||
try (/Loading.loaded).modify(&value) { | ||
$0 += "!!!" | ||
} | ||
|
||
if case let .loaded(string) = value { | ||
value = .loaded(string + "!!!") | ||
} | ||
} | ||
|
||
// CasePath<Loading, String>(Loading.loaded) | ||
|
||
//CasePath( | ||
// embed: Loading.loaded, | ||
// extract: { | ||
// guard case let .loaded(value) = $0 | ||
// else { return nil } | ||
// return value | ||
// } | ||
//) |
10 changes: 10 additions & 0 deletions
10
...ro-case-paths-pt2/CasePathExplorations/CasePathExplorations/CasePathExplorationsApp.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 CasePathExplorationsApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
EmptyView() | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...thExplorations/CasePathExplorations/Preview Content/Preview Assets.xcassets/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...-paths-pt2/CasePathExplorations/CasePathExplorationsTests/CasePathExplorationsTests.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,36 @@ | ||
// | ||
// CasePathExplorationsTests.swift | ||
// CasePathExplorationsTests | ||
// | ||
// Created by Point-Free on 10/18/23. | ||
// | ||
|
||
import XCTest | ||
@testable import CasePathExplorations | ||
|
||
final class CasePathExplorationsTests: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testExample() throws { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct results. | ||
// Any test you write for XCTest can be annotated as throws and async. | ||
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. | ||
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. | ||
} | ||
|
||
func testPerformanceExample() throws { | ||
// This is an example of a performance test case. | ||
self.measure { | ||
// Put the code you want to measure the time of here. | ||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...hs-pt2/CasePathExplorations/CasePathExplorationsUITests/CasePathExplorationsUITests.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,41 @@ | ||
// | ||
// CasePathExplorationsUITests.swift | ||
// CasePathExplorationsUITests | ||
// | ||
// Created by Point-Free on 10/18/23. | ||
// | ||
|
||
import XCTest | ||
|
||
final class CasePathExplorationsUITests: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
|
||
// In UI tests it is usually best to stop immediately when a failure occurs. | ||
continueAfterFailure = false | ||
|
||
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testExample() throws { | ||
// UI tests must launch the application that they test. | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
// Use XCTAssert and related functions to verify your tests produce the correct results. | ||
} | ||
|
||
func testLaunchPerformance() throws { | ||
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { | ||
// This measures how long it takes to launch your application. | ||
measure(metrics: [XCTApplicationLaunchMetric()]) { | ||
XCUIApplication().launch() | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...PathExplorations/CasePathExplorationsUITests/CasePathExplorationsUITestsLaunchTests.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,32 @@ | ||
// | ||
// CasePathExplorationsUITestsLaunchTests.swift | ||
// CasePathExplorationsUITests | ||
// | ||
// Created by Point-Free on 10/18/23. | ||
// | ||
|
||
import XCTest | ||
|
||
final class CasePathExplorationsUITestsLaunchTests: XCTestCase { | ||
|
||
override class var runsForEachTargetApplicationUIConfiguration: Bool { | ||
true | ||
} | ||
|
||
override func setUpWithError() throws { | ||
continueAfterFailure = false | ||
} | ||
|
||
func testLaunch() throws { | ||
let app = XCUIApplication() | ||
app.launch() | ||
|
||
// Insert steps here to perform after app launch but before taking a screenshot, | ||
// such as logging into a test account or navigating somewhere in the app | ||
|
||
let attachment = XCTAttachment(screenshot: app.screenshot()) | ||
attachment.name = "Launch Screen" | ||
attachment.lifetime = .keepAlways | ||
add(attachment) | ||
} | ||
} |
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,5 @@ | ||
## [Point-Free](https://www.pointfree.co) | ||
|
||
> #### This directory contains code from Point-Free Episode: [Macro Case Paths: Part 2](https://www.pointfree.co/episodes/ep258-macro-case-paths-part-2) | ||
> | ||
> We have now totally reimagined the design of our case paths library to create actual key paths for enum cases, but there is some boilerplate involved. Let’s create a macro that eliminates all of it and explore a few of the possibilities it unlocks. |
Oops, something went wrong.