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

Use-cases for Swift interop in .NET 10 #95636

Open
Tracked by #95638
kotlarmilos opened this issue Dec 5, 2023 · 5 comments
Open
Tracked by #95638

Use-cases for Swift interop in .NET 10 #95636

kotlarmilos opened this issue Dec 5, 2023 · 5 comments
Assignees
Labels
area-Meta os-ios Apple iOS os-mac-os-x macOS aka OSX tracking This issue is tracking the completion of other related issues. User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@kotlarmilos
Copy link
Member

kotlarmilos commented Dec 5, 2023

Overview

This issue presents use-cases we want to support. They are required to define and limit the scope of Swift interop effort in .NET 10. While it's difficult to clearly specify the exact Swift language features that will be supported in the next release, we can establish our definition of done.

Milestone 1 – StoreKit2 purchase MVP

Implement basic purchase functionality without UI components. Below is an example of Swift pseudo code.

func requestProducts() async {
    do {
        let storeProducts = try await Product.products(for: productIdentifiers)
        products = storeProducts
    } catch {
        print("Error fetching products: \(error)")
    }
}

func purchase(_ product: Product) async throws -> Transaction? {
    let result = try await product.purchase()
    return result
}

Objectives

  • Establish projection tooling skeleton: parsers->marshalers->emitters
  • Project structs and it's members
  • Project Swift runtime features: metadata, value witness table, and async
  • Project optional types
  • Project Swift errors/exceptions in C#
  • Project StoreKit2 types with its members needed for the basic purchase functionality. Specifically:
    • struct Product : Swift.Identifiable {}
    • struct Transaction : Swift.Identifiable {}

Deliverables

Risks

  • Work items are too broad, which may affect group focus
  • Significant fundamental work on the projection tooling in a single iteration

Milestone 2 – Subscriptions and list purchased products

Implement advanced purchase experience with subscriptions and list of already purchased products. Below is an example of Swift pseudo code.

func updateProductStatus() async {
    var purchasedProducts: [Product] = []

    for await result in Transaction.currentEntitlements {
        do {
            switch transaction.productType {
            case .nonConsumable:
                //
            case .nonRenewable:
                // 
            case .autoRenewable:
                // 
            default:
                break
            }
        } catch {
            print("Transaction failed verification: \(error)")
        }
    }
}

Objectives

  • Project enums and it's members
  • Project StoreKit2 types needed for subscriptions purchase functionality. Specifically:
    • struct Transaction : Swift.Identifiable {}
    • struct SubscriptionPeriod : Swift.Equatable, Swift.Hashable {}
    • struct SubscriptionOffer : Swift.Equatable, Swift.Hashable {}
    • struct RenewalState : Swift.RawRepresentable, Swift.Equatable, Swift.Hashable {}
    • struct RenewalInfo {}
    • struct ExpirationReason : Swift.RawRepresentable, Swift.Equatable, Swift.Hashable {}
    • struct SubscriptionInfo : Swift.Equatable, Swift.Hashable {}
    • enum StoreKitError : Swift.Error {}
    • enum PurchaseResult {}
    • enum VerificationResult<SignedType> {}

Deliverables

Risks

  • Limited functionality due to dependencies on other frameworks

Milestone 3 – Pack StoreKit2 bindings in the experimental NuGet

Pack and distribute StoreKit2 bindings for supported scenarios.

Objectives

  • Distribute StoreKit2 bindings
  • Lock the design of projection tooling input: ABI parser and MacO reader
  • Learn limitations of the bindings

Deliverables

Risks

  • Limited functionality due to dependencies on other frameworks
  • Incomplete / non-functional bindings
  • Poor UX

This is the first end-to-end milestone. All following milestones are informational/ tentative only, and will be updated according to the progress.

Milestone 4 – Basic SwiftUI controls

Integrate native SwiftUI controls into a MAUI-based app. Below is an example of Swift pseudo code.

 public func getTextView() -> UIView {
     let swiftUIView = Text("Hello from Swift!").font(.title)
     let hostingController = UIHostingController(rootView: swiftUIView)
     return hostingController.view
}

Objectives

  • Project SwiftUI types needed for a simple UI example. Specifically:
    • struct Text {}
    • struct Button<Label> where Label : View {}
    • struct Label<Title, Icon> where Title : View, Icon : View {}
    • struct Image {}
    • class UIHostingController<Content> where Content : View

Deliverables

Milestone 5 – Support StoreKit2 views using SwiftUI

Integrate advanced SwiftUI views into MAUI-based app.

Objectives

  • Project StoreKit2 views for improved UX. Specifically:
    • struct ProductView {}
    • struct StoreView {}
    • struct SubscriptionStoreView {}

Deliverables

Milestone 6 – Pack SwiftUI in the experimental NuGet

Pack and distribute SwiftUI bindings for supported scenarios.

Objectives

  • Distribute SwiftUI bindings
  • Lock the design of projection tooling output: string-based and model-based emitters
  • Learn limitations of the bindings

Deliverables

Milestone 7 – Test all the frameworks from the SDK

Objectives

  • Run the tooling on all SDK frameworks to test coverage
  • Distribute the projection tooling

Deliverables

Milestone 8 - Deploy the Hiking app

Deploy experimental .NET iOS app which demonstrate the capabilities of the nSwift interop.

Objectives

  • Implement in-app purchase
  • Implement authentication feature using the built-in SignInWithAppleButton
  • Integrate native SwiftUI controls into MAUI-based applications

Note

The .NET iOS app with generated bindings will be experimental in .NET 10 and will not be officially supported.

@kotlarmilos kotlarmilos added area-Meta User Story A single user-facing feature. Can be grouped under an epic. labels Dec 5, 2023
@kotlarmilos kotlarmilos added this to the 9.0.0 milestone Dec 5, 2023
@kotlarmilos kotlarmilos self-assigned this Dec 5, 2023
@ghost
Copy link

ghost commented Dec 5, 2023

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

This issue tracks the top-level scenarios for end-users regarding .NET Swift interop. The goal is to demonstrate the practical application of .NET Swift interop within Maui scenarios. One possible approach is to select an existing Maui sample from https://github.com/dotnet/maui-samples and improve it by incorporating native libraries and widgets, such as UIKit or SwiftUI. There are some other ideas, which may be desirable but not required, and will be added later.

Below is a list of tasks that needs to be implemented. Please note that the breakdown of the issues does not impose hard deadlines. If some of the functionality does not get upstreamed for a particular preview version, this issue will be updated accordingly.

Tasks

.NET9 Preview 1

  • Compile a list of libraries and features to support in .NET 9
  • Select Maui applications to showcase the .NET Swift interop
  • Propose design for VSCode extension

.NET9 Preview 2

  • Update Maui applications to utilize the .NET Swift interop
  • Implement and deploy the VSCode extension

.NET9 Preview 3

  • Implement telemetry for BTfS usage
  • Write a blog post that showcases the usage of .NET Swift interop

.NET9 Preview 4

TBD

Author: kotlarmilos
Assignees: kotlarmilos
Labels:

area-Meta, User Story

Milestone: 9.0.0

@kotlarmilos kotlarmilos changed the title [Tracking] End-users scenarios for .NET Swift interop in .NET 9 [Tracking] End-users scenarios for .NET Swift interop Dec 5, 2023
@kotlarmilos kotlarmilos changed the title [Tracking] End-users scenarios for .NET Swift interop [Tracking] End-user scenarios for .NET Swift interop Dec 5, 2023
@kotlarmilos kotlarmilos added the tracking This issue is tracking the completion of other related issues. label Dec 5, 2023
@kotlarmilos kotlarmilos changed the title [Tracking] End-user scenarios for .NET Swift interop End-user scenarios for .NET Swift interop Dec 5, 2023
@kotlarmilos kotlarmilos changed the title End-user scenarios for .NET Swift interop Crat Feb 12, 2024
@kotlarmilos kotlarmilos changed the title Crat Create dev templates for CryptoKit library Feb 12, 2024
@kotlarmilos kotlarmilos changed the title Create dev templates for CryptoKit library End-user scenarios for .NET Swift interop Feb 22, 2024
@jeffhandley jeffhandley added os-mac-os-x macOS aka OSX os-ios Apple iOS labels Aug 6, 2024
@vitek-karas vitek-karas modified the milestones: 9.0.0, 10.0.0 Aug 22, 2024
@kotlarmilos kotlarmilos changed the title End-user scenarios for .NET Swift interop Use-cases for Swift interop in .NET 10 Oct 8, 2024
@clarky07
Copy link

clarky07 commented Dec 5, 2024

I think live activity support would make sense for this (and lots of other use cases). Just commenting here as a suggestion I got from another issue.

@kotlarmilos
Copy link
Member Author

Thanks, there is a tracking issue: xamarin/xamarin-macios#17038

@amirvenus
Copy link

There are also some libraries available in Swift such as Apple's MLX.

It would be great if one could easily interop into Swift from .net.

@kotlarmilos
Copy link
Member Author

There are also some libraries available in Swift such as Apple's MLX.

Created a tracking issue: xamarin/xamarin-macios#21811

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Meta os-ios Apple iOS os-mac-os-x macOS aka OSX tracking This issue is tracking the completion of other related issues. User Story A single user-facing feature. Can be grouped under an epic.
Projects
None yet
Development

No branches or pull requests

5 participants