DrasticPicker 1.0.2

dotnet add package DrasticPicker --version 1.0.2
NuGet\Install-Package DrasticPicker -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DrasticPicker" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DrasticPicker --version 1.0.2
#r "nuget: DrasticPicker, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DrasticPicker as a Cake Addin
#addin nuget:?package=DrasticPicker&version=1.0.2

// Install DrasticPicker as a Cake Tool
#tool nuget:?package=DrasticPicker&version=1.0.2

DrasticPicker

Access the SwiftUI Picker controller in .NET iOS, tvOS, and Catalyst apps.

NuGet Version License

Catalyst Logo

How To Use

  • Check the sample directory for a sample app.
var picker = new PickerViewWrapper(
            "Sample Picker", 
            new[] { "Options 1", "Options 2" },
            "Options 2",
            CustomPickerStyle.Menu,
            action =>
            {
                Console.WriteLine(action);
            });
this.View!.AddSubview(picker.UIView);
  • PickerViewWrapper is an NSObject that contains the SwiftUI view. Once initialized, you can access the UIView by requesting its property.

From that point on, it's a standard UIView and can be treated as such.

FAQ

Q: Why does this exist?

In the Desktop Idiom, Mac Catalyst does not support UIPickerView. Your app will throw an exception if you try to use it. Normally, in an ObjC/Swift app, you could bring in SwiftUI and use its Picker as a replacement. SwiftUI isn't bound for .NET, and there's no direct interop process for accessing Swift inside of .NET apps, so there's no direct way to call for a SwiftUI Picker. This library gives a hacky way to make that happen.

Q: Why does this not support macOS AppKit?

I believe it could, by replacing the UIHostingController wrapper with an AppKit version, but since AppKit already has the pickers I need, I didn't bother. But if you want that, you should be able to do it if you add the support within the library framework itself, fix its breaking changes, and rebind it.

Product Compatible and additional computed target framework versions.
.NET net8.0-ios17.0 is compatible.  net8.0-maccatalyst17.0 is compatible.  net8.0-tvos17.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0-ios17.0

    • No dependencies.
  • net8.0-maccatalyst17.0

    • No dependencies.
  • net8.0-tvos17.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 166 12/25/2023