Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize app example #231

Merged
merged 5 commits into from
Dec 6, 2021
Merged

Modernize app example #231

merged 5 commits into from
Dec 6, 2021

Conversation

stevapple
Copy link
Contributor

@stevapple stevapple commented Sep 25, 2021

Update LocalDebugging example to reflect the latest SwiftUI practice.

Motivation:

Since we already required Swift 5.5 with Concurrency (Xcode 13), it's natural to update the app part to reflect latest SwiftUI changes, which makes the code neater and more expressive.

Modifications:

  • Update LocalDebugging/MyApp to use SwiftUI lifecycle;
  • Update LocalDebugging/MyApp to reflect SwiftUI best practice;
  • Update LocalDebugging/Shared to use Swift 5.5.

Result:

A better demo app.

@swift-server-bot
Copy link

Can one of the admins verify this patch?

6 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@stevapple stevapple force-pushed the update-app branch 2 times, most recently from 8a1e613 to 0ebb9dd Compare September 25, 2021 03:09
@tomerd tomerd added the patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Sep 25, 2021
@tomerd
Copy link
Contributor

tomerd commented Sep 25, 2021

thank @stevapple !

lets get #228 in first

@tomerd
Copy link
Contributor

tomerd commented Sep 25, 2021

@swift-server-bot test this please

@stevapple
Copy link
Contributor Author

I've rebased the branch against #228, so there should be no pain to merge.

@tomerd
Copy link
Contributor

tomerd commented Sep 26, 2021

@swift-server-bot test this please

@tomerd
Copy link
Contributor

tomerd commented Sep 27, 2021

@swift-server-bot test this please

@@ -58,22 +67,16 @@ struct ContentView: View {
let (data, response) = try await URLSession.shared.data(for: request)

guard let httpResponse = response as? HTTPURLResponse else {
throw CommunicationError(reason: "invalid response, expected HTTPURLResponse")
return "invalid response, expected HTTPURLResponse"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally not a big fan of removing the CommunicationError here, since it hides what actually happens. We need to have some do {} catch {} somewhere else. This method should be async throws -> String.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh yes.

I changed it into () async -> String because we need to ensure the label is changed in every path. throws could be preserved here and it doesn't affect.

Copy link
Member

@fabianfett fabianfett Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer something like this:

func register() await -> String {
    do {
        return try await self.runNetworkRegister(name: self.name, password: self.password)
    } catch as CommunicationError {
        return error.reason
    } catch {
        return error.localizedDescription
    }
}

Copy link
Contributor Author

@stevapple stevapple Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather suggest we catch in the button action? The register() API is expected not to confuse an actual response and a thrown Error. runNetworkRegister(name:password:) looks redundant here.

Copy link
Contributor Author

@stevapple stevapple Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional catch can also be eliminated here by implementing LocalizedError.

Copy link
Member

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait for @tomerd approval!

@fabianfett
Copy link
Member

@tomerd ping

@tomerd
Copy link
Contributor

tomerd commented Oct 2, 2021

@swift-server-bot test this please

@stevapple
Copy link
Contributor Author

Xcode 13.2 and Swift Playgrounds 4 supports a new type of package-based app project (.swiftpm), and a preview of it can be seen here.

I’m wondering if such change is too aggressive as most of us still use .xcodeproj in production. @fabianfett @tomerd

@stevapple
Copy link
Contributor Author

ping @tomerd @fabianfett

@fabianfett fabianfett merged commit 39b34a1 into swift-server:main Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants