Requirements
| iOS / iPadOS | 16.4+ |
| macOS | 13.3+ |
| visionOS | 1.0+ |
| Swift tools | 5.9+ (Xcode 15+) |
Install
In Xcode choose File ▸ Add Package Dependencies…, enter https://github.com/EqviLabs/m3ekit-swift.git and add the M3EKit product to your app target. In a package manifest:
dependencies: [
.package(url: "https://github.com/EqviLabs/m3ekit-swift.git", from: "0.1.0"),
],
targets: [
.target(name: "App", dependencies: [.product(name: "M3EKit", package: "m3ekit-swift")]),
]Setup
Apply a theme once, at the root. Every M3EKit view below it reads colors, type, shapes and motion from it.
import M3EKit
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.m3eTheme(seed: 0x6750A4, variant: .tonalSpot) // light + dark, follows the system
}
}
}Without a theme, components use the Material 3 baseline palette and still follow light and dark mode.
First screen
struct ContentView: View {
@State private var range: Set<Int> = [0]
@State private var liked = false
@State private var fabOpen = false
@Environment(\.m3eTheme) private var theme
var body: some View {
VStack(alignment: .leading, spacing: 20) {
Text("This week").m3eTextStyle(.headlineMedium, emphasized: true)
M3EButtonGroup(items: [.init("Day"), .init("Week"), .init("Month")], selection: $range)
HStack(spacing: 16) {
M3EMaterialShape(liked ? .heart : .circle).frame(width: 56)
M3EIconToggleButton("favorite_border", checkedIcon: "favorite", isOn: $liked, variant: .tonal)
}
M3ELinearWavyProgressIndicator(progress: 0.6)
M3EButton("Start run", icon: "directions_run", size: .medium) { start() }
}
.padding(24)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.background(theme.colors.surface)
.overlay(alignment: .bottomTrailing) {
M3EFabMenu(isExpanded: $fabOpen, items: [
.init("Walk", icon: "directions_walk") {},
.init("Ride", icon: "directions_bike") {},
])
.padding(24)
}
}
}Theming
From a seed color
view.m3eTheme(seed: 0x006A6A, variant: .expressive, contrast: 0.5)
let dark = M3ETheme(seed: 0x006A6A, dark: true, variant: .vibrant)Variants: tonalSpot, expressive, vibrant, fidelity, content, neutral, monochrome, rainbow, fruitSalad. Contrast runs from -1 to 1. The generator is a Swift port of Material Color Utilities.
Brand colors, fonts and motion
let brand = M3ETheme(
colors: M3EColorScheme([.primary: Color(m3eHex: 0x006A6A), .onPrimary: .white]),
typography: .baseline(brandFontFamily: "Fraunces"),
motion: .expressive // or .standard for calmer motion
)
let brandDark = M3ETheme(dark: true, colors: M3EColorScheme(dark: true, [.primary: Color(m3eHex: 0x4CDADA)]))
ContentView().m3eTheme(light: brand, dark: brandDark)Material Theme Builder
let theme = try M3ETheme.fromThemeBuilder(jsonData, dark: false)Using tokens in your own views
@Environment(\.m3eTheme) private var theme
Text("Inbox")
.m3eTextStyle(.titleLarge, emphasized: true)
.foregroundStyle(theme.colors.onSurface)
.padding(theme.shapes.medium)
.background(theme.colors.surfaceContainer, in: RoundedRectangle(cornerRadius: theme.shapes.large))
.animation(theme.motion.defaultSpatial.animation, value: expanded)Components
Every component has its own page with design, code, API and guidelines.
| Component | SwiftUI |
|---|---|
| Button | M3EButton |
| Icon button | M3EIconButton |
| FAB | M3EFab |
| FAB menu | M3EFabMenu |
| Button group | M3EButtonGroup |
| Split button | M3ESplitButton |
| Switch | M3ESwitch |
| Checkbox | M3ECheckbox |
| Radio button | M3ERadioButton |
| Slider | M3ESlider |
| Chip | M3EChip |
| Loading indicator | M3ELoadingIndicator |
| Wavy progress | M3ELinearWavyProgressIndicator |
| Material shape | M3EMaterialShape |
| Navigation bar | M3ENavigationBar |
| Navigation rail | M3ENavigationRail |
| Tabs | M3ETabs |
| Toolbars | M3EFloatingToolbar |
| Top app bar | M3ETopAppBar |
| Carousel | M3ECarousel |
| Card | M3ECard |
| List item | M3EListItem |
| Text field | M3ETextField |
| Search bar | M3ESearchBar |
| Menu | M3EMenu |
| Dialog, sheet, snackbar, tooltip | |
Icons
Pass Material Symbols names ("add", "arrow_back", "favorite"). They map to matching SF Symbols. A name containing a dot ("heart.fill") is used as an SF Symbol directly, and "asset:Name" loads an image from your asset catalog. Use M3EIcon("edit") in your own views.
Overrides
Every interactive component takes overrides:. Anything you set there wins over the theme and size tokens.
M3EButton("Brand", overrides: .init(containerColor: .orange, contentColor: .white,
cornerRadius: 6, pressedCornerRadius: 18)) {}
M3EButton("Tall", overrides: .init(height: 64, paddingHorizontal: 36, fontSize: 20, fontWeight: .bold)) {}Available keys: containerColor, contentColor, checkedContainerColor, checkedContentColor, borderColor, borderWidth, cornerRadius, pressedCornerRadius, checkedCornerRadius, height, paddingHorizontal, iconSize, iconSpacing, fontSize, fontWeight, fontFamily, letterSpacing, elevation, gap.
Accessibility
- Text scales with Dynamic Type. Turn it off for a subtree with
.m3eFontScaling(false), for example in a fixed-size badge. - Icon-only controls take
accessibilityLabel:; always pass one. - Toggles, checkboxes, radios and switches expose their state to VoiceOver.
- Continuous animations respect Reduce Motion (the loading indicator keeps only its slow rotation).
- iOS presses use light haptics; pass
haptics: falseto disable them per control.
Platform notes
- iOS: menus draw in a window-level overlay, so they are never clipped by scroll views or cells.
- macOS: menus open in a popover; text fields use the plain style so no AppKit bezel shows; there are no haptics.
- visionOS: menus open in a popover; there are no haptics.
Best practices
- Theme once at the root; nest
.m3eThemeonly to re-theme a section (a card, a sheet) on purpose. - Use theme roles for your own views so they follow the seed color and dark mode.
- Prefer
M3EMaterialShape(spinDuration:)over custom rotation animations; it runs on Core Animation. - Keep progress state in the smallest view that shows it.
- Use
.disabled(true)to disable any control, rather than lowering opacity yourself.
Troubleshooting
| Problem | Fix |
|---|---|
| “Minimum deployment target” build error | Raise the target to iOS 16.4 / macOS 13.3. |
| An icon shows as a placeholder | That Material name has no SF Symbol mapping; pass an SF Symbol name with a dot, or asset:Name. |
| Colors ignore my brand | Apply .m3eTheme above the views, not on a sibling. |
| A menu is cut off on macOS | Menus are popovers on macOS; give the anchor room or use .m3eMenu(isPresented:) on a larger view. |
AI prompt
Paste this into Claude Code, Codex, Cursor, Antigravity or any coding agent to integrate M3EKit into your project.
SwiftUI
Integrate M3EKit into an iOS, macOS or visionOS SwiftUI app.
You are integrating M3EKit (Material 3 Expressive for SwiftUI) into this project.
About the library:
- Package: https://github.com/EqviLabs/m3ekit-swift.git, product "M3EKit", from: "0.1.0". iOS 16.4+, macOS 13.3+, visionOS 1+. No dependencies.
- Components: M3EButton, M3EToggleButton, M3EIconButton, M3EIconToggleButton, M3EFab, M3EExtendedFab, M3EFabMenu, M3EButtonGroup, M3ESplitButton, M3EMenu / .m3eMenu, M3ELoadingIndicator, M3ELinearWavyProgressIndicator, M3ECircularWavyProgressIndicator, M3EMaterialShape + M3EShape (35 shapes, usable as SwiftUI Shape), M3ESwitch, M3ECheckbox, M3ERadioButton, M3ESlider, M3ERangeSlider, M3EChip, M3ETabs, M3ENavigationBar, M3ENavigationRail, M3EFloatingToolbar, M3EDockedToolbar, M3ETopAppBar, M3ECarousel, M3ECard, M3EListItem, M3EDivider, M3EBadge / .m3eBadge, M3ETextField, M3ESearchBar, .m3eDialog, .m3eBottomSheet, .m3eSnackbar, .m3eTooltip.
- Icons are Material Symbols names ("arrow_forward", "favorite") mapped to SF Symbols; names containing "." are SF Symbols.
Steps:
1. Add the Swift package (Xcode: File > Add Package Dependencies, or Package.swift: .package(url: "https://github.com/EqviLabs/m3ekit-swift.git", from: "0.1.0") and .product(name: "M3EKit", package: "m3ekit-swift")). Raise the deployment target to iOS 16.4 if lower.
2. Theme once at the root: ContentView().m3eTheme(seed: 0xRRGGBB, variant: .tonalSpot) using the app's brand color as the seed. Ask me for the brand color if it isn't obvious from the asset catalog or existing theme.
3. In your own views read tokens with @Environment(\.m3eTheme) var theme (theme.colors.surface, theme.colors.onSurface, …) and text styles with .m3eTextStyle(.titleMedium). Replace hard-coded colors you touch with roles.
4. Replace custom buttons, toggles, progress views, segmented controls and FABs with the M3EKit equivalents. Keep behavior identical; only change presentation.
5. Use .overrides only when the design requires a value the tokens don't have; prefer theme changes.
Design rules (apply on every screen you touch):
- Color: use theme color roles (primary, onPrimary, primaryContainer, onPrimaryContainer, secondaryContainer, tertiaryContainer, surface, surfaceContainer*, onSurface, onSurfaceVariant, outlineVariant). Never hard-code hex values in components. Always pair a container with its "on" role for text and icons on it.
- Hierarchy: one filled button per area for the primary action; tonal or outlined for secondary; text buttons for low emphasis.
- Shapes: use M3E shapes with intent (avatars, image masks, loaders, state changes). One strong shape per area beats many.
- Motion: use the library's springs; don't add your own timing curves to M3EKit components. Respect Reduce Motion.
- Progress: loading indicator for short indeterminate waits; wavy progress when you know how far along it is; use flat for progress that sits still for long.
- Accessibility: every icon-only control gets an accessibility label; keep touch targets at least 48dp; don't put text on busy shapes (burst, boom).
- Keep fast-changing state (progress, slider values) in the smallest component that needs it.
SwiftUI specifics:
- Bind state with @State / @Binding as the components expect (isOn:, selection:, isExpanded:). Don't wrap them in extra gesture recognizers.
- M3EMaterialShape(spinDuration:) runs on Core Animation; prefer it to custom rotation animations.
- Use .disabled(true) to disable any control.
When done:
- Build for every platform the app targets and fix all warnings you introduced.
- Run the app and check light and dark mode, Dynamic Type at a large size, and VoiceOver labels on icon-only controls.
- Summarize what you changed, file by file.