This Package is related to Gitee. If you feel that the introduction of Github addresses in SPM is slow, you can use Gitee.
Built-in various auxiliary development tools, and the newly added API after iOS15 is compatible with iOS14, please run the demo to view the usage of specific functions
Versions before 1.0.0 support iOS14, while versions after 1.0.0 use iOS16+Swift6.0
BrickKit provides a comprehensive AGENTS.md file that serves as an AI Skills reference for AI-powered development tools (Cursor, opencode, GitHub Copilot, etc.). This guide helps AI assistants understand the library's structure and generate correct code.
When working on a project that uses BrickKit, the AI assistant will automatically reference AGENTS.md to:
- Understand the library structure - Complete directory tree of all components
- Generate correct code - Usage examples for every API
- Add bilingual comments - Chinese/English comment format guidelines
- Follow conventions -
Brick<Wrapped>pattern, naming conventions, etc.
Simply ensure AGENTS.md is in your project root. AI tools will automatically read it as context:
YourProject/
├── AGENTS.md ← AI Skills reference (copy from BrickKit)
├── Package.swift
└── Sources/
Or reference it directly in your AI tool's configuration:
// .cursorrules or similar config
{
"contextFiles": ["path/to/BrickKit/AGENTS.md"]
}When asking AI to help with BrickKit:
Using BrickKit, create a list with pull-to-refresh and load more.
The AI will reference AGENTS.md and generate:
List {
ForEach(items) { item in
Text(item.name)
}
LoadMoreView { loadMoreItems() }
}
.emptyPlaceholder(items) {
Text("No items")
}
.enableRefresh(true)
.onRefresh { refreshItems() }| Section | Content |
|---|---|
| Directory Structure | Complete file tree of SwiftUI/, Wrapped/, Utilities/, Tools/ |
| SwiftUI Extensions | Usage examples for all 24 SwiftUI extensions |
| Wrapped Usage | 30 Wrapped component examples (view.ss.xxx) |
| Utilities | Core utilities (SFSymbols, Keyboard, Adapter, etc.) |
| Tools Usage | 27 Tools folder examples (Toast, Loading, Picker, etc.) |
| Comment Guidelines | Bilingual comment format for consistency |
Adds functionality to View using the Brick<Wrapped> pattern, call via view.ss.xxx
import Brick
// Usage
view.ss.tabBar(.hidden)
view.ss.onChange(of: value) { newValue in }| Feature | Description | Usage |
|---|---|---|
| TabbarVisible | Control TabBar visibility with animation | view.ss.tabBar(.hidden) |
| AppStore | Generate App Store URL and present product page | view.ss.showStoreProduct(appID: "123") |
| OnChange | Unified onChange handler, iOS 14-17 compatible | view.ss.onChange(of: value) { newValue in } |
| ShareSheet | Custom share sheet | ShareSheetView(activityItems: [...]) |
| Checkmark | Custom checkbox toggle style | view.ss.checkmark(.visible) / Toggle("Check", isOn: $bool).toggleStyle(.checkmark) |
| Geometry | Geometry change detection & visual effects | view.ss.onGeometryChange(for: CGSize.self, of: { $0.size }) { old, new in } |
| Badge | Badge overlay system | view.ss.badge { Text("99+") } |
| BottomSafeArea | Custom bottom safe area inset | view.ss.bottomSafeAreaInset { SomeView() } |
| Border | Border modifier | view.ss.border(.red, cornerRadius: 8, lineWidth: 2) |
| Background | Background modifier, hide List/TextView background | view.ss.background { Color.blue } / view.ss.hideListBackground() |
| Alignment | Adjust view alignment | view.ss.alignmentGuideAdjustment(anchor: .topLeading) |
| CustomBackButton | Custom navigation back button | view.ss.navigationCustomBackButton { Image(systemName: "chevron.left") } |
| Task | Backported .task modifier for iOS 14- | view.ss.task { await doSomething() } |
| TabbarColor | Set TabBar background color | view.ss.tabbarColor(.white) |
| Submit | Form submission, custom keyboard return key | view.ss.onSubmit { submit() } / view.ss.submitLabel(.done) |
| SafeArea | Safe area padding | view.ss.safeAreaPadding(16) |
| OnTapLocal | Get tap location coordinates | view.ss.onTapGesture { point in print(point) } |
| NavigationBarColor | Set navigation bar background color | view.ss.navigationBarColor(backgroundColor: .blue) |
| ListSpace | Set List section spacing | view.ss.listSectionSpace(20) |
| Hidden | Conditional view hiding with transition | view.ss.hidden(isHidden, transition: .opacity) |
| PushTransition | Edge push/pop transition (iOS 16+) | AnyTransition.ss.push(from: .leading) |
| Overlay | Overlay modifier | view.ss.overlay { SomeView() } |
| Section | Backported Section container for iOS 14- | Brick.Section("Title") { content } |
| ProposedViewSize | Proposed view size struct | ProposedViewSize.zero / .infinity / .unspecified |
| RequestReview | App Store review request | @Environment(\.requestReview) var requestReview |
| Shadow | Shadow modifier | view.ss.shadow(color: .black, x: 0, y: 2, blur: 4) |
| NavigationTitle | Navigation title with display mode | view.ss.navigationTitle("Title", displayMode: .large) |
| Mask | Inverted mask for badge effects | view.ss.invertedMask { Circle() } |
| Corner | Specific corner radius | view.ss.cornerRadius(10, corners: [.topLeft, .topRight]) |
| Alert | UIAlertController button tint | .alert("Title").ss.alertButtonTint(.white) |
// Control TabBar visibility
view.ss.tabBar(.hidden) // Hide TabBar
view.ss.tabBar(.visible) // Show TabBar// iOS 14-17 compatible onChange
view.ss.onChange(of: count) { newValue in
print("New value: \(newValue)")
}
// With initial value callback (iOS 17+)
view.ss.onChange(of: value, initial: true) { oldValue, newValue in
print("Changed from \(oldValue) to \(newValue)")
}
// No parameter closure
view.ss.onChange(of: flag) {
print("Flag changed")
}// Listen to view size changes
view.ss.onGeometryChange(for: CGSize.self, of: { $0.size }) { oldSize, newSize in
print("Size changed: \(oldSize) -> \(newSize)")
}
// Get new value only
view.ss.onGeometryChange(for: CGSize.self, of: { $0.size }) { newSize in
print("New size: \(newSize)")
}
// Visual effect
view.ss.visualEffect { anyView, proxy in
someView
.frame(width: proxy.size.width)
}// Basic badge
view.ss.badge {
Text("99+")
.font(.caption)
.foregroundColor(.white)
.padding(4)
.background(Color.red)
.clipShape(Circle())
}
// Custom config
view.ss.badge(
alignment: .topTrailing,
anchor: UnitPoint(x: 0.3, y: 0.3),
scale: 1.2,
inset: 8
) {
redCircle
}// Rounded rectangle border
view.ss.border(Color.blue, cornerRadius: 12, lineWidth: 2)
// Capsule border
view.ss.borderCapsule(Color.green, lineWidth: 1)
// Custom shape border
view.ss.border(LinearGradient(...), width: 3, cornerRadius: 8)// Basic async task
view.ss.task {
let data = await fetchData()
print(data)
}
// With priority
view.ss.task(priority: .background) {
await heavyWork()
}
// Task with ID cancellation (re-executes when value changes)
view.ss.task(id: itemId) {
await fetchItem(itemId)
}// Submit action
TextField("Enter text", text: $text)
.ss.onSubmit {
submitForm()
}
// Submit label (keyboard return key)
TextField("Username", text: $username)
.ss.submitLabel(.next)
TextField("Password", text: $password)
.ss.submitLabel(.done)// Uniform padding
view.ss.safeAreaPadding(16)
// Specific edges
view.ss.safeAreaPadding(.horizontal, 20)
// Using EdgeInsets
view.ss.safeAreaPadding(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))Hidden - Conditional Hiding
// Simple hiding
view.ss.hidden(isLoading)
// With transition
view.ss.hidden(isHidden, transition: .slide)
view.ss.hidden(isHidden, transition: .scale)
view.ss.hidden(isHidden, transition: .opacity)import UIKit
// Top corners only
view.ss.cornerRadius(10, corners: [.topLeft, .topRight])
// Bottom corners only
view.ss.cornerRadius(10, corners: [.bottomLeft, .bottomRight])
// Top-left only
view.ss.cornerRadius(10, corners: [.topLeft]) view.ss.shadow(color: .black.opacity(0.2), x: 0, y: 4, blur: 8)// View modifier
view.ss.checkmark(.visible)
// Toggle style
Toggle(" Agree to terms", isOn: $agreed)
.toggleStyle(.checkmark)SwiftUI type extensions providing convenient functionality for SwiftUI development.
| Feature | Description | Usage |
|---|---|---|
| View++ | View extensions: .then(), .hidden(), .offset(), .fill(), .fit(), .hideKeyboard() |
view.then { $0.padding() } |
| ForEach++ | ForEach enhancement: index access, .interleave(), .interdivided(), .interspaced() |
ForEach(items) { item in } |
| View+Geometry | Bind view geometry: bindSafeAreaInsets, bindSize |
view.bindSize($size) |
| View+Haptic | Haptic feedback: HapticButton, tap/change/selection feedback |
.hapticFeedback(.success) |
| View+Frame | Frame extensions: .minWidth(), .maxWidth(), .height(), .readHeight() |
.minWidth(100) |
| View+Mask | Mask extensions: .mask(), .masking(), .reverseMask() |
.reverseMask { Circle() } |
| View+Background | Background extensions: PassthroughView, .backgroundFill() |
.backgroundFill(Color.blue) |
| Image++ | Image extensions: .symbol(), .resized(), .sizeToFit() |
Image(systemName: "heart").symbol(...) |
| View+Conditionals | Conditional views: .enabled(), .hidden(if), .visible(if) |
.hidden(if: isHidden) |
| Text++ | Text extensions | Text("Hello").bold() |
| Label++ | Label extensions | Label("Title", systemImage: "star") |
| List++ | List extensions | List { ... }.listStyle(.insetGrouped) |
| Section++ | Section extensions | Section("Header") { ... } |
| NavigationLink++ | NavigationLink extensions | NavigationLink(destination: View) |
| Shape++ | Shape extensions | Circle(), RoundedRectangle() |
| Spacer++ | Spacer extensions | Spacer().frame(height: 10) |
| Menu++ | Menu extensions | Menu { ... } |
| Angle++ | Angle extensions | Angle(degrees: 45) |
| Collection++ | Collection extensions | [1,2,3].safeSubscript(0) |
| URL++ | URL extensions | URL(string: "...") |
| String++ | String extensions | "hello".localized |
| Task+ | Task extensions | Task.sleep(1000000000) |
| GridItem++ | GridItem extensions | GridItem(.flexible()) |
// Chain view modifications
view.then { $0.padding() }
.then { $0.background(Color.blue) }
// Conditional hiding
view.hidden(isHidden)
// Offset helpers
view.offset(point)
view.offset(length)
view.inset(length)
// Fill/Fit parent view
view.fill(alignment: .center)
view.fit()
// Transition
view.transition(.scale)
view.asymmetricTransition(insertion: .opacity, removal: .move(edge: .leading))
// Type erasure
view.eraseToAnyView()
view.any()
// Hide keyboard (iOS)
view.hideKeyboard()
// Conditional tap gesture
view.onTapGesture(count: 2, disabled: isDisabled) {
// handle tap
}
// Fill parent view
view.fill(alignment: .center)
// Fit parent view (maintain aspect ratio)
view.fit()
// Set tint color
view.tintColor(.red)
// Conditional tap on background
view.onTapGestureOnBackground {
// handle background tap
}// With index access
ForEach(items, id: \.id) { index, item in
Text("\(index): \(item.name)")
}
// Interleave with separator
ForEach(items) { item in
Text(item.name)
}.interleave(with: Divider())
// Interdivide (with Divider)
ForEach(items) { item in
Text(item.name)
}.interdivided()
// Interspaced (with Spacer)
ForEach(items) { item in
Text(item.name)
}.interspaced()@State private var size: CGSize = .zero
@State private var safeArea: EdgeInsets = .zero
view.bindSize(to: $size)
view.bindSafeAreaInsets(to: $safeArea)// Haptic button
HapticButton {
print("tapped")
} label: {
Text("Tap me")
}
// Haptic feedback
hapticFeedback()
hapticFeedback(type: .success)
hapticFeedback(type: .medium)
// View haptics modifiers
view.haptics(onChangeOf: value, type: .success)
view.haptics(when: status, equalsTo: "success", type: .warning)
view.haptics(onChangeOf: count, type: .light)
view.triggersHapticFeedbackWhenAppear()// Min/Max width & height
view.minWidth(100)
view.maxWidth(200)
view.minHeight(50)
view.maxHeight(150)
// Width & height
view.width(100)
view.height(50)
// Relative size
view.relativeWidth(0.5)
view.relativeHeight(0.3)
view.relativeSize(width: 0.5, height: 0.3)
// Read size
view.readHeight { height in print(height) }
view.readWidth { width in print(width) }
// Square frame
view.squareFrame()
view.squareFrame(sideLength: 100)
// Ideal frame
view.idealFrame(width: 100, height: 50)// Mask
view.mask(Circle())
// Masking (inverse)
view.masking {
Circle()
}
// Reverse mask (for badge effects)
view.reverseMask(alignment: .topTrailing) {
Circle()
.frame(width: 20, height: 20)
}// Background
view.background(Color.red)
view.background {
Image("bg")
}
// Background fill (ignoring safe area)
view.backgroundFill(Color.blue)
view.backgroundFill {
LinearGradient(...)
}
// PassthroughView
PassthroughView {
Color.red
}// Symbol with config
Image(systemName: "heart")
.symbol(variableColor: .blue)
.symbolRenderingMode(.hierarchical)
// Resize image
Image(systemName: "heart")
.resized(toWidth: 100)
.resized(toHeight: 50)
// Size to fit
image.sizeToFit()
// Load async image
AsyncImage(url: url)
.loadAsync()// Enable/disable view
view.enabled(isEnabled)
view.enabled(isEnabled, removeFromHierarchy: true)
// Conditional visibility
view.hidden(if: isHidden)
view.visible(if: isVisible)
// Conditional modifier
view.modifier(if: shouldApply) {
SomeModifier()
}// Text styling
Text("Hello")
.bold()
.italic()
.underline()
.strikethrough()
.monospaced()
.smallCaps()
.textCase(.uppercase)
.textCase(.lowercase)
// Tracking
Text("Hello")
.tracking(2)
.tracking(-0.5)// Label with icon
Label("Title", systemImage: "star")
Label {
Text("Content")
} icon: {
Image(systemName: "star")
}// List with style
List {
// content
}
.listStyle(.insetGrouped)
.listStyle(.plain)
.listStyle(.inset)
.listStyle(.sidebar)
// List row background
.listRowBackground(Color.clear)// Section with header
Section("Header") {
Text("Content")
}
// Section with header and footer
Section(header: Text("Header"), footer: Text("Footer")) {
Text("Content")
}// Push navigation
NavigationLink(destination: DetailView()) {
Text("Go to Detail")
}
// Value-based navigation
NavigationLink(value: item) {
Text(item.name)
}
.navigationDestination(for: Item.self) { item in
DetailView(item: item)
}// Rounded rectangle
RoundedRectangle(cornerRadius: 10)
RoundedRectangle(cornerRadius: 10, style: .continuous)
// Capsule
Capsule()
Capsule(style: .continuous)
// Custom shapes
Rectangle()
Circle()
Ellipse()// Spacer with min length
Spacer(minLength: 20)
// Spacer with frame
Spacer()
.frame(height: 10)// Basic menu
Menu("Actions") {
Button("Action 1") { }
Button("Action 2") { }
}
// Menu with label
Menu {
Button("Edit") { }
Button("Delete") { }
} label: {
Image(systemName: "ellipsis.circle")
}// Angle from degrees
Angle(degrees: 45)
// Angle from radians
Angle(radians: .pi / 4)
// Rotate content
content
.rotationEffect(Angle(degrees: 45))// Safe subscript
let item = array[safe: 0] // Returns nil if out of bounds
// First/last
array[safe: \.first]
array[safe: \.last]
// Boundary safe
array[safe: 0...5]
array[safe: 0..<5]// URL with query parameters
var components = URL(string: "https://example.com")
components?.queryItems = [
URLQueryItem(name: "key", value: "value")
]
// Check URL validity
url?.isValid// Case transformations
"hello".uppercasedFirst() // "Hello"
"hello".lowercasedFirst() // "hello"
"hello_world".camelcased() // "helloWorld"
"HelloWorld".snakecased() // "hello_world"
"hello world".titlecased() // "Hello World"
// URL encoding
"hello world".urlEscaped() // "hello%20world"
// Line handling
"line1\nline2".lines() // ["line1", "line2"]
// Whitespace handling
" hello world ".trimmed() // "hello world"
// Pattern replacement
"hello".replacing("l", with: "r") // "herro"
// Validation
"https://example.com".isValidUrl // true
" ".isBlank // true
// Prefix/suffix removal
"hello world".droppingPrefix("hello ") // "world"
"hello world".droppingSuffix(" world") // "hello"
// Take last characters
"hello".take(last: 3) // "llo"
// Random string
String.random(length: 10)
// Truncation
"Hello World".truncate(5) // "He..."
"Hello World".truncate(5, position: .head) // "...rld"
"Hello World".truncate(5, position: .middle) // "He...ld"
// Nil if empty/blank
"".nilIfEmpty // nil
" ".nilIfBlank // nil// Sleep
try? await Task.sleep(1_000_000_000) // 1 second
// Task with timeout
try? await Task.timeout(after: 1.0) {
await someWork()
}// Flexible grid item
GridItem(.flexible())
GridItem(.flexible(spacing: 10))
GridItem(.flexible(spacing: 10, alignment: .leading))
// Fixed grid item
GridItem(.fixed(100))
GridItem.fixed(100)
// Adaptive grid item
GridItem.adaptive(minimum: 50, maximum: 100)
// Array of grid items
[GridItem].fixed([100, 200, 100])
[GridItem].adaptive(minimum: 80, maximum: .infinity)
[GridItem].flexible(minimum: 50, maximum: 200)
// GridItem.Size
GridItem.Size.adaptive(100)Pre-built UI components for rapid development.
| Feature | Description | Usage |
|---|---|---|
| NavigationStack | Navigation stack (iOS 16-) + Navigation API | Brick.NavigationStack { ... } / Navigator.push() |
| Navigation | Navigation item, swipe back, path helpers | .navigationItem() / .regainSwipeBack() |
| Page | Paging scroll view with PageIndicator | PageScrollView(pageOutWidth: 50, pagePadding: 10) { ... } |
| Animation | Animation helpers: onAnimationCompleted, withAnimation completion | view.onAnimationCompleted(for: value) { } |
| Blur | Blur effects: BlurView, GlassBlurView, GlassmorphismBlurView | BlurView() / GlassBlurView(removeAllFilters: true) |
| Date | Date utilities: Date+, DateFormatter, JSONEncoder/Decoder | Date(year: 2024, month: 1, day: 1) |
| Toast | Toast messages with position (top/bottom), animation types | Toast.show("Message") |
| ListPicker | Generic list picker with sections, single/multi selection | ListPicker(selection: $value, items: []) |
| TTextField | Custom styled text field with title, placeholder, error states | TTextField(title: "Name", text: $text) |
| CarouselView | Horizontal carousel with scaling, wrapping, auto-scroll | CarouselView(items: []) |
| FlipView | 3D flip card view | FlipView(front: View, back: View) |
| OpenUrl | URL opening: OpenURL, Link, Safari, WebView | Brick.Link("Text", destination: url) / WebView(url: url) |
| WebView | WebView component | WebView(url: url) |
| Presentation | Presentation controls: DragIndicator, Detents, CornerRadius | presentationDetents([.medium, .large]) |
| TextEditors | TextEditor style extensions | TextEditor(text: $text).style(...) |
| UnderLineText | Underline text input | UnderLineText(text: $text) |
| UIHostingConfiguration | UIKit cell content configuration | UIHostingConfiguration { ... } |
| Loading | Loading overlay with animation + LoadingManager | .loading(isPresented: $loading) { ... } / LoadingManager() |
| Keychain | Keychain storage utilities | KeychainService.shared.set(value, forKey: "key") |
| ScrollView | ScrollView helpers: indicators, keyboard dismiss, enabled | .ss.scrollIndicators(.hidden) |
| ScrollStack | Lazy scrollable stacks and grids | VScrollStack { ... } / HScrollStack { ... } |
| Gestures | Gesture buttons with press, long press, double tap, repeat, swipe | GestureButton { ... } |
| Triangle | Triangle shape | Triangle() / Triangle(inverted: true) |
| RoundedCorner | Rounded corner shape | RoundedCorner(radius: 10) |
| CustomSegmentPicker | Custom segmented picker | CustomSegmentPicker(selection: $index, segments: []) |
| Others | Misc: FlipView, MarqueeText, RadioButton, OtpView, ExpandText, etc | FlipView(front: View, back: View) |
// Navigation item customization
NavigationView {
ContentView()
}
.navigationItem(animated: true) { item in
item.title = "My Title"
}
// Hide back button title
NavigationView {
ContentView()
}
.hiddenBackButtonTitle()
// Restore swipe back gesture
ContentView()
.regainSwipeBack()
// Navigation path (iOS 16+)
@StateObject var path = NavigatorPath()
path.path.push("NewScreen")
path.path.pop()
path.path.popTo(index: 0)
path.path.popToRoot()// Basic navigation stack (cross-version)
Brick.NavigationStack {
VStack {
Text("Root View")
}
}
// With typed path
@State var path: [MyScreen] = []
Brick.NavigationStack(path: $path) {
ContentView()
}
// Using Navigator
@EnvironmentObject var navigator: Navigator<MyScreen>
// Push a screen
navigator.push(.detail)
// Pop screens
navigator.pop() // Pop 1
navigator.pop(2) // Pop 2
navigator.popToRoot() // Pop to root
navigator.popTo(index: 0)
navigator.popTo(where: { $0 == .home })
// Navigation link
Brick.NavigationLink("Go to Detail", value: MyScreen.detail)
// Navigation destination
.navigationDestination(isPresented: $showDetail) {
DetailView()
}
// Use SwiftUI NavigationStack policy
.useNavigationStack(.whenAvailable) // or .never// Basic carousel
CarouselView(items, id: \.id) { item in
Image(item.imageURL)
.resizable()
.aspectRatio(contentMode: .fill)
}
.index($currentIndex)
// With custom configuration
CarouselView(
items,
id: \.id,
index: $currentIndex,
spacing: 10,
headspace: 20,
sidesScaling: 0.85,
isWrap: true,
autoScroll: .active(3),
canMove: true
) { item in
BannerView(item: item)
}
// Auto scroll options
CarouselAutoScroll.inactive // No auto scroll
CarouselAutoScroll.active(5) // Auto scroll every 5 seconds
CarouselAutoScroll.defaultActive // Default 5 seconds// Basic page scroll view
@State private var currentPage = 0
PageScrollView(pageOutWidth: 50, pagePadding: 10) {
ForEach(0..<10, id: \.self) { index in
RoundedRectangle(cornerRadius: 20)
.fill(.orange)
.overlay {
Text("Page \(index)")
}
}
}
.frame(height: 228)
// With PageIndicator
VStack {
PageScrollView(pageOutWidth: 40, pagePadding: 20) {
ForEach(bannerItems) { item in
BannerView(item: item)
}
}
.frame(height: 200)
PageIndicatorView(
numPages: bannerItems.count,
currentPage: $currentPage,
height: 8,
currentWidth: 20,
spacing: 8,
color: .white
)
}
.background(Color.black)// Animation completion callback
@State private var scale: CGFloat = 1.0
Button("Animate") {
withAnimation(.spring()) {
scale = 1.5
}
}
.onAnimationCompleted(for: scale) {
// Called when animation completes
print("Animation completed!")
}
// With animation completion handler
withAnimation(.easeInOut(duration: 0.5), after: 0.5, completion: {
print("Done!")
}) {
isAnimated.toggle()
}
// Delayed animation
withAnimation(.spring(), after: 1.0) {
viewModel.update()
}
// Check if transaction is animated
let transaction = Transaction(animation: .default)
let isAnimated = transaction.isAnimated // true
// Disable animations
withoutAnimation {
updateWithoutAnimation()
}// Basic blur view (iOS/tvOS)
BlurView()
.frame(height: 200)
// Glass blur effect (iOS 15+)
GlassBlurView(removeAllFilters: false)
.frame(height: 180)
// With custom background
GlassBlurView(removeAllFilters: true)
.blur(radius: 5, opaque: true)
.background(.black.opacity(0.8))
.frame(height: 180)
// Glassmorphism blur effect
GlassmorphismBlurView()
.frame(width: 300, height: 200)// Initialize date with components
let date = Date(year: 2024, month: 1, day: 15, hour: 12, minute: 30)
// Date comparison
date.isAfter(anotherDate) // true/false
date.isBefore(anotherDate) // true/false
date.isSame(as: anotherDate) // true/false
// Add time
let tomorrow = date.adding(days: 1)
let nextHour = date.adding(hours: 1)
let in30Minutes = date.adding(minutes: 30)
// Remove time
let yesterday = date.removing(days: 1)
// Get date components
let year = date.year // 2024
let month = date.month // 1
let day = date.day // 15
let hour = date.hour // 12
let minute = date.minute // 30
let second = date.second // 0
// Calculate date difference
let daysDiff = date.days(from: anotherDate)
let hoursDiff = date.hours(from: anotherDate)
let minutesDiff = date.minutes(from: anotherDate)
// Calendar helpers
let isToday = Calendar.current.isDateToday(date)
let isThisWeek = Calendar.current.isDateThisWeek(date)
let isThisMonth = Calendar.current.isDateThisMonth(date)
// DateFormatter
let formatter = DateFormatter(dateFormat: "yyyy-MM-dd HH:mm:ss")
let formatted = formatter.string(from: date)
// ISO8601 JSON encoding/decoding
let encoder = JSONEncoder.iso8601
let decoder = JSONDecoder.iso8601// Basic NavigationStack (iOS 14-15 compatible, deprecated on iOS 16+)
@State private var path: [String] = []
Brick.NavigationStack(path: $path) {
List {
ForEach(items, id: \.self) { item in
NavigationLink(item, value: item)
}
}
.navigationDestination(for: String.self) { item in
DetailView(item: item)
}
}
// Without path binding (internal path management)
Brick.NavigationStack {
List {
NavigationLink("Detail", value: "detail1")
NavigationLink("Detail", value: "detail2")
}
.navigationDestination(for: String.self) { value in
DetailView(title: value)
}
}
// Using Navigator (programmatic navigation)
@EnvironmentObject var navigator: Navigator<String>
Button("Push Detail") {
navigator.push("newDetail")
}
Button("Pop") {
navigator.pop()
}
Button("Pop to Root") {
navigator.popToRoot()
}
Button("Pop to Index") {
navigator.popTo(index: 2)
}
Button("Pop to Condition") {
navigator.popTo(where: { $0 == "target" })
}
// Using PathNavigator (AnyHashable)
@EnvironmentObject var pathNavigator: PathNavigator
pathNavigator.push("newScreen")
pathNavigator.popTo(String.self)
// Custom Navigation Policy
struct ContentView: View {
var body: some View {
NavigationStack(path: $path) {
// Content
}
.environment(\.useNavigationStack, .whenAvailable) // Use NavigationStack when available (iOS 16+)
.environment(\.useNavigationStack, .never) // Always use NavigationView (iOS 14-15)
}
}// OpenURL - Custom URL open action
@Environment(\.openURL) var openURL
Button("Open Website") {
if let url = URL(string: "https://www.example.com") {
openURL(url)
}
}
// With completion handler
openURL(url) { accepted in
print(accepted ? "Success" : "Failure")
}
// Custom URL handler
Text("Visit [Example](https://www.example.com)")
.environment(\.openURL, Brick.OpenURLAction { url in
handleURL(url)
return .handled
})
// Link - URL link component
Brick.Link("View Terms", destination: URL(string: "https://www.example.com/TOS.html")!)
// With custom openURL
Brick.Link("Visit Site", destination: URL(string: "https://www.example.com")!)
.environment(\.openURL, Brick.OpenURLAction { url in
print("Open \(url)")
return .handled
})
// Safari - Open in Safari (with SFSafariViewController)
Brick.OpenURLAction.Result.safari(url)
// With custom configuration
Brick.OpenURLAction.Result.safari(url) { config in
config.prefersReader = true
config.barCollapsingEnabled = false
config.dismissStyle = .close
config.tintColor = .blue
}
// WebView - WKWebView component
WebView(url: URL(string: "https://www.example.com")!)
.showProgress(true)
.setProgressColor(.green)
.showRefreshControl(true)
.clearBackgroundColor()
.setCookies([cookie1, cookie2])
.localStorageItem("value", forKey: "key")
.getWebViewState($state)
.getWebViewObject($webView)
// WebView with JS message handler
WebView(url: url)
.onMessageHandler(name: "handlerName") { body in
print("Received: \(body ?? "")")
}
// Clean all web data
WebView.Coordinator.cleanAllWebsiteDataStoreIfNeeded()// Basic usage
@State private var text = ""
TTextField(text: $text)
.tTextFieldTitle("Username")
.tTextFieldPlaceHolderText("Enter username")
.tTextFieldTextColor(.black)
.tTextFieldTitleColor(.gray)
// With error state
@State private var hasError = false
@State private var errorMessage = "Invalid input"
TTextField(text: $text, error: $hasError, errorText: $errorMessage)
.tTextFieldTitle("Email")
.tTextFieldPlaceHolderText("Enter email")
// Secure text field
TTextField(text: $password)
.tTextFieldSecure(true)
.tTextFieldSecureImage(open: .eye, close: .eyeSlash)
// Custom styling
TTextField(text: $text)
.tTextFieldTitleFont(.headline)
.tTextFieldErrorFont(.caption)
.tTextFieldPlaceHolderFont(.subheadline)
.tTextFieldBackgroundColor(.white)
.tTextFieldBorderColor(.gray)
.tTextFieldErrorTextColor(.red)
.tTextFieldFocusedBorderColor(.blue)
.tTextFieldFocusedBorderColorEnable(true)
.tTextFieldBorderType(.square)
.tTextFieldBorderWidth(1)
.tTextFieldCornerRadius(8)
.tTextFieldHeight(44)
// With leading/trailing views
TTextField(text: $text)
.tTextFieldLeadingView {
Image(systemName: "person")
.foregroundColor(.gray)
}
.tTextFieldTrailingView {
Button(action: {}) {
Image(systemName: "xmark.circle.fill")
}
}
// Input limits
TTextField(text: $text)
.tTextFieldLimitCount(20)
.tTextFieldTruncationMode(.tail)
// Disable auto-correction
TTextField(text: $text)
.tTextFieldDisableAutoCorrection(true)// Basic single selection picker
@State private var selectedItem: Item?
ListPicker(selection: $selectedItem, items: items) { item, isSelected in
ListSelectItem(isSelected: isSelected) {
Text(item.name)
}
}
// With sections
@State private var selected: Item?
ListPicker(
sections: [
ListPickerSection(title: "Section 1", items: items1),
ListPickerSection(title: "Section 2", items: items2)
],
selection: $selected
) { item, isSelected in
ListSelectItem(isSelected: isSelected) {
HStack {
Image(item.icon)
Text(item.name)
}
}
}
// Multi selection picker
@State private var selectedItems: [Item] = []
ListMultiPicker(selection: $selectedItems, items: items) { item, isSelected in
ListSelectItem(isSelected: isSelected) {
Text(item.name)
}
}
// With custom indicator
ListSelectItem(isSelected: isSelected, selectIndicator: Image(systemName: "checkmark.circle.fill")) {
Text("Item name")
}
// Optional binding fallback
@State private var optionalValue: Double?
func doSomething(with binding: Binding<Double>) { ... }
doSomething(with: $optionalValue ?? 0)// Detents (iOS 15+)
.sheet(isPresented: $showSheet) {
ContentView()
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
}
// With selection binding
@State private var selectedDetent: PresentationDetent = .medium
.sheet(isPresented: $showSheet) {
ContentView()
.presentationDetents([.medium, .large], selection: $selectedDetent)
}
// Interactive dismiss
.sheet(isPresented: $showSheet) {
ContentView()
.interactiveDismissDisabled() // Disable dismiss
}
// Custom corner radius (iOS 15+)
.sheet(isPresented: $showSheet) {
ContentView()
.presentationCornerRadius(20)
}
// Background interaction
.sheet(isPresented: $showSheet) {
ContentView()
.presentationBackground(Color.clear)
.presentationBackgroundInteraction(.upwards)
}
// Content interaction
.sheet(isPresented: $showSheet) {
ContentView()
.contentShapeSumo(.rect)
}// Basic loading
@State private var isLoading = false
Button("Show Loading") {
isLoading = true
}
.loading(isPresented: $isLoading) {
ProgressView()
.scaleEffect(1.5)
}
// With options
.loading(
isPresented: $isLoading,
options: LoadingOptions(
hideAfter: 3.0, // Auto hide after 3 seconds
backdrop: .black.opacity(0.5), // Dark backdrop
animation: .easeInOut,
modifierType: .fade, // or .scale
dismissOnTap: true // Tap to dismiss
)
) {
VStack {
ProgressView()
Text("Loading...")
.foregroundColor(.white)
}
.padding(30)
.background(Color.gray.opacity(0.8))
.cornerRadius(10)
}
// Using LoadingManager (programmatic)
let manager = LoadingManager()
// Add to your root view
MyRootView()
.addLoading(manager)
// Show different types
manager.text = "Please wait..."
manager.showLoading()
manager.text = "Loading: 50%"
manager.progress = 0.5
manager.showProgress()
manager.text = "Success!"
manager.showSuccess()
manager.text = "Failed!"
manager.showFail()
// Hide
manager.hide()
// Custom styling
manager.textColor = .white
manager.textFont = .headline
manager.accentColor = .blue
manager.maskColor = .black.opacity(0.5)// Using KeychainService (recommended)
let service = KeychainService.shared
// Save values
service.set("John", forKey: "name")
service.set(25, forKey: "age")
service.set(true, forKey: "isEnabled")
service.set(Data(), forKey: "data")
// Read values
let name: String? = service.string(forKey: "name")
let age: Int? = service.integer(forKey: "age")
let isEnabled: Bool? = service.bool(forKey: "isEnabled")
let data: Data? = service.data(forKey: "data")
// Check if value exists
let hasName = service.hasValue(forKey: "name")
// Delete value
service.removeObject(forKey: "name")
// Delete all keys
service.removeAllKeys()
// Using KeychainWrapper directly
let wrapper = KeychainWrapper(serviceName: "com.example.app")
wrapper.set("secret", forKey: "password")
let password = wrapper.string(forKey: "password")
// With accessibility
wrapper.set("data", forKey: "key", with: .whenUnlocked)
// Clear entire keychain (use with caution!)
KeychainWrapper.wipeKeychain()// Using LanguageSettings (singleton)
let settings = LanguageSettings.shared
// Get current language
let currentLanguage = settings.selectedLanguage
// Set language
settings.selectedLanguage = .en
settings.selectedLanguage = .zhHans
// Get device language
let deviceLang = settings.deviceLanguage
// Check layout direction (for RTL languages like Arabic, Hebrew)
let isRTL = settings.isRightToLeft
let layoutDirection = settings.layout
// Using LanguageView to wrap content
LanguageView {
VStack {
Text("Hello")
Text("World")
}
}
// This will automatically apply the correct locale and layout direction
// String localization
let localizedString = "hello_world".localized
let formattedString = "greeting_message".localized.with("John", "Hello")
// Get available languages
let languages = Localize.getList()
let available = Localize.availableLanguages()
// Select language view (navigation ready)
NavigationStack {
SelectLanguageView()
}// Empty placeholder - show view when list is empty
@State private var items: [String] = []
List {
ForEach(items, id: \.self) { item in
Text(item)
}
}
.emptyPlaceholder(items) {
VStack {
Image(systemName: "tray")
.font(.largeTitle)
Text("No items")
.foregroundColor(.secondary)
}
}
// Load more - trigger when scrolled into view (place in LazyVStack)
LazyVStack {
ForEach(items, id: \.self) { item in
Text(item)
}
LoadMoreView {
// Load more items when reached
loadMoreItems()
}
}// Linear Progress Bar
@State private var progress: Double = 0.5
LinearProgressBar(progress: progress)
.linearProgressBarStyle(.standard)
// With custom style
LinearProgressBar(progress: 0.8)
.linearProgressBarStyle(.padding)
LinearProgressBar(progress: 0.6)
.linearProgressBarStyle(.tallPadding)
// Custom style
extension LinearProgressBar.Style {
static var customStyle: LinearProgressBar.Style = {
var style = LinearProgressBar.Style.standard
style.backgroundColor = .gray.opacity(0.2)
style.barColor = .blue
style.height = 8
style.animation = .easeInOut
return style
}()
}
LinearProgressBar(progress: 0.7)
.linearProgressBarStyle(.customStyle)
// Circular Progress Bar
CircularProgressBar(progress: 0.65)
.circularProgressBarStyle(.standard)
// Without text
CircularProgressBar(progress: 0.8)
.circularProgressBarStyle(.noText)
// Custom circular style
CircularProgressBar(progress: 0.9)
.circularProgressBarStyle(CircularProgressBar.Style(
animation: .easeIn(duration: 3),
backgroundColor: .blue,
decimals: 2,
strokeColor: .yellow,
strokeWidth: 5,
startAngle: 45,
progressColor: .yellow,
progressWidth: 15,
titleColor: .yellow,
titleFont: .title.bold()
))
// ProgressView with custom style
ProgressView(value: 0.5)
.progressViewStyle(.heightBar(height: 10, foregroundColor: .blue))
ProgressView(value: 0.7)
.progressViewStyle(.heightBar(
height: 6,
foregroundColor: .green,
backgroundColor: .gray.opacity(0.3)
))
// Circular progress style
ProgressView(value: 0.6)
.progressViewStyle(CircularProgressStyle(strokeColor: .blue, strokeWidth: 8))
// Flickering view (loading animation)
FlickeringView(count: 5)
.frame(width: 100, height: 100)
.foregroundColor(.blue)// Enable pull-to-refresh on List
@State private var isRefreshing = false
List(items, id: \.id) { item in
Text(item.name)
}
.enableRefresh(true)
// With default header
List(items, id: \.id) { item in
Text(item.name)
}
.enableRefresh(true)
.refreshHeader {
DefaultRefreshHeader(refreshing: $isRefreshing, refreshText: "Pull to refresh") {
// Refresh action - load new data
await loadData()
isRefreshing = false
}
}
// Custom header with progress
@State private var refreshing = false
List(items, id: \.id) { item in
Text(item.name)
}
.enableRefresh(true)
.refreshHeader {
Refresh.Header(refreshing: $refreshing) { progress in
// progress: 0.0 to 1.0+ (triggers refresh at > 1.0)
VStack {
if refreshing {
ProgressView()
} else {
Text("Pull down: \(Int(progress * 100))%")
}
}
} action: {
await loadData()
}
}
// With default footer (load more)
@State private var isLoadingMore = false
List(items, id: \.id) { item in
Text(item.name)
}
.enableRefresh(true)
.refreshFooter {
DefaultFooter(refreshing: $isLoadingMore, noMoreText: "No more data") {
await loadMore()
}
}
// Custom footer with no more state
@State private var loading = false
@State private var hasMoreData = true
List(items, id: \.id) { item in
Text(item.name)
}
.enableRefresh(true)
.refreshFooter {
Refresh.Footer(refreshing: $loading) {
HStack {
if loading {
ProgressView()
Text("Loading more...")
}
}
}
.noMore(!hasMoreData) // Hide footer when no more data
.preload(offset: 50) // Trigger 50pt before reaching bottom
}
// Refresh namespace types
typealias RefreshHeader = Refresh.Header
typealias RefreshFooter = Refresh.Footer
typealias DefaultRefreshHeader = Refresh.DefaultHeader
typealias DefaultRefreshFooter = Refresh.DefaultFooter// Hide scroll indicators
ScrollView {
VStack(alignment: .leading) {
ForEach(0..<100) {
Text("Row \($0)")
}
}
}
.ss.scrollIndicators(.hidden)
// Show specific axis indicators
ScrollView {
LazyVStack {
ForEach(0..<50, id: \.self) { i in
Text("Item \(i)")
}
}
}
.ss.scrollIndicators(.visible, axes: .vertical)
// Disable scrolling
@State private var isScrollDisabled = false
ScrollView {
VStack {
Toggle("Disable", isOn: $isScrollDisabled)
MyContent()
}
}
.ss.scrollDisabled(isScrollDisabled)
// Keyboard dismiss behavior
@State var text = ""
ScrollView {
TextField("Prompt", text: $text)
ForEach(0 ..< 50) { index in
Text("\(index)")
.padding()
}
}
.ss.scrollDismissesKeyboard(.immediately)
// Different keyboard dismissal modes
.ss.scrollDismissesKeyboard(.automatic) // Default behavior
.ss.scrollDismissesKeyboard(.interactively) // Interactive dismissal
.ss.scrollDismissesKeyboard(.never) // Never dismiss
// ScrollViewTracking - Track scroll position
@State private var currentScroll: CGFloat = 0
ScrollTrackingView(currentScroll: $currentScroll) {
ForEach(0..<20, id: \.self) { index in
Text("Item \(index)")
.padding()
}
}
// Use onScroll to listen to scroll changes
.onScroll { offset in
print("Scroll offset: \(offset)")
}// Basic usage
@State private var text = ""
@State private var date = Date()
UnderLineText()
.underLineText(text)
.underLineTitle("Name")
.underLineColor(.gray)
// With leading/trailing views
UnderLineText()
.underLineText("Some Text")
.underLineTitle("Label")
.underLineLeadingView {
Image(systemName: "person")
}
.underLineTrailingView {
DatePicker("", selection: $date, displayedComponents: .date)
}
// Custom styling
UnderLineText()
.underLineText("Custom")
.underLineTitle("Title")
.underLineTitleColor(.gray)
.underLineTitleFont(.headline)
.underLineTextColor(.black)
.underLineTextFont(.body)
.underLineColor(.blue)
.underLineHeight(1)
.underLineTextHeight(40)// Basic usage
@State private var text = ""
TextEditors("Enter your text here", text: $text)
.frame(height: 150)
.border(Color.gray)
// With custom padding
TextEditors("Placeholder text", text: $text)
.padding(10)
.background(Color.gray.opacity(0.1))
.cornerRadius(8)
// With text limit
@State private var limitedText = ""
TextEditors("Max 100 characters", text: $limitedText, textLimit: 100)
.frame(height: 100)// Automatic/Plain style
TextEditor(text: $text)
.textEditorStyle(.automatic)
// Rounded border
TextEditor(text: $text)
.textEditorStyle(.roundedBorder)
// Custom color border
TextEditor(text: $text)
.textEditorStyle(.roundedColorBorder(.blue, 2))
// Custom color with different width
TextEditor(text: $text)
.textEditorStyle(.roundedColorBorder(.red, 5))// For UITableViewCell
cell.contentConfiguration = UIHostingConfiguration {
HStack {
Image(systemName: "star")
.foregroundStyle(.purple)
Text("Favorites")
Spacer()
}
}
// With background
cell.contentConfiguration = UIHostingConfiguration {
HStack {
Image(systemName: "star")
.foregroundStyle(.purple)
Text("Favorites")
Spacer()
}
}
.background {
Color.blue
}
// With margins
cell.contentConfiguration = UIHostingConfiguration {
Text("My Contents")
}
.margins(.horizontal, 20)
.margins(.vertical, 10)
// For UICollectionViewCell
collectionCell.contentConfiguration = UIHostingConfiguration {
VStack {
Image(systemName: "photo")
.resizable()
.aspectRatio(contentMode: .fill)
Text("Image Title")
}
}
.background(Color.gray.opacity(0.1))
.margins(.all, 8)// Basic upward triangle
Triangle()
.fill(Color.blue)
// Inverted (downward) triangle
Triangle(inverted: true)
.fill(Color.red)
// With stroke
Triangle()
.stroke(Color.green, lineWidth: 2)
// Custom size
Triangle()
.frame(width: 100, height: 100)
.fill(Color.orange)// All corners rounded
RoundedCorner(radius: 20, corners: .allCorners)
.fill(Color.gray)
// Specific corners (iOS)
RoundedCorner(radius: 10, corners: [.topLeft, .topRight])
.fill(Color.blue)
RoundedCorner(radius: 15, corners: [.bottomLeft, .bottomRight])
.fill(Color.green)
// Single corner
RoundedCorner(radius: 25, corners: .topLeft)
.fill(Color.red)
// Apply to view
Rectangle()
.clipShape(RoundedCorner(radius: 20, corners: .allCorners))// Define segment items
struct SegmentItem: Identifiable {
let id = UUID()
let title: String
}
@State private var selectedSegment: SegmentItem
// Basic usage
CustomSegmentPicker(
segments: segments,
selected: $selectedSegment,
content: { item in
Text(item.title)
.padding()
},
background: {
Capsule()
}
)
// With custom colors
CustomSegmentPicker(
segments: segments,
selected: $selectedSegment,
normalColor: .gray,
selectedColor: .white,
selectedBackColor: .blue,
bgColor: .gray.opacity(0.2),
animation: .easeInOut(duration: 0.3),
content: { item in
HStack {
Image(systemName: item.icon)
Text(item.title)
}
.padding()
},
background: {
RoundedRectangle(cornerRadius: 10)
}
)
// With RoundedRectangle background
CustomSegmentPicker(
segments: items,
selected: $selectedItem,
normalColor: .black,
selectedColor: .white,
selectedBackColor: .orange,
bgColor: .gray.opacity(0.3),
content: { item in
Text(item.name)
.font(.headline)
},
background: {
RoundedRectangle(cornerRadius: 8)
}
)// FlipView - 3D flip card
@State private var isFlipped = false
FlipView(
front: Color.green,
back: Color.red,
isFlipped: $isFlipped,
flipDuration: 0.5,
tapDirection: .right,
swipeDirections: [.left, .right, .up, .down]
)
// MarqueeText - Scrolling text
MarqueeText("This is a long text that will scroll automatically")
MarqueeText("Custom speed", spacing: 10, speed: 2.0)
// RadioButton - Radio button with label
RadioButton(isSelected: false, label: "Option 1") { isSelected in
print("Selected: \(isSelected)")
}
// OtpView - OTP verification code input
OtpView(activeColor: .blue, inActiveColor: .gray, length: 4) { code in
print("Entered code: \(code)")
}
// ExpandText - Expandable text
ExpandText(lineLimit: 2, animation: .easeInOut(duration: 0.2)) {
Text("This is a long text that will be cropped to 2 lines initially. Tap to expand.")
} moreView: { action in
Button(" ... more", action: action)
}
// CountDownTimerText - Countdown timer
CountDownTimerText(timeCount: 60, timeUnit: "s", titleWhenIdle: "Get Code", titleWhenFinished: "Send Again", mode: .manual) {
return true // Return true to start countdown
}
// AutoHeightTextEditor - Auto height text editor
@State private var text = ""
@State private var placeholder = "Enter text..."
@FocusState private var isFocused: Bool
AutoHeightTextEditor(
inputText: $text,
placeholder: $placeholder,
textFocused: $isFocused
)
// RightArrow - Add right chevron arrow
Text("Settings")
.addRightArrow()
// RichText - Rich text with separator
Text(separator: " ") {
Text("Hello")
.font(.headline)
.foregroundColor(.red)
Text("World")
.fontWeight(.light)
}
// AnyButtonStyle - Custom button style
Button("Click me") {}
.buttonStyle { config in
config.label
.padding()
.background(config.isPressed ? Color.gray : Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
// AppColorScheme - App theme management
@StateObject var colorScheme = AppColorScheme()
colorScheme.darkModeSetting = .dark // or .light, .system
// AnyViewModifier - Type-erased view modifier
let modifier = AnyViewModifier { content in
content
.padding()
.background(Color.blue)
}// Vertical scroll stack (VStack with scrolling)
VScrollStack(spacing: 10, showsIndicators: true) {
ForEach(0..<20, id: \.self) { index in
Text("Item \(index)")
.padding()
}
}
// Horizontal scroll stack (HStack with scrolling)
HScrollStack(spacing: 15, showsIndicators: false) {
ForEach(0..<10, id: \.self) { index in
Image(systemName: "star.fill")
.font(.largeTitle)
}
}
// Vertical scroll grid (3 columns)
VScrollGrid(rowsCount: 3, spacing: 10) {
ForEach(0..<12, id: \.self) { index in
RoundedRectangle(cornerRadius: 8)
.fill(Color.blue.opacity(0.6))
.frame(height: 60)
}
}
// Horizontal scroll grid (2 rows)
HScrollGrid(rowsCount: 2, spacing: 10) {
ForEach(0..<8, id: \.self) { index in
RoundedRectangle(cornerRadius: 8)
.fill(Color.green.opacity(0.6))
.frame(width: 80)
}
}
// Fixed width columns
VScrollGrid.fixedColumns(widths: [80, 120, 80], spacing: 8) {
ForEach(0..<9, id: \.self) { index in
Text("Col \(index)")
}
}
// Adaptive columns (auto-fit)
VScrollGrid.adaptiveColumns(minimum: 100, spacing: 10) {
ForEach(0..<15, id: \.self) { index in
Text("Item \(index)")
}
}
// Single row horizontal grid (common for horizontal lists)
HScrollGrid.singleRow(height: 80, spacing: 12) {
ForEach(0..<10, id: \.self) { index in
RoundedRectangle(cornerRadius: 12)
.fill(Color.mint.opacity(0.7))
.frame(width: 100)
}
}// Gesture button (not for ScrollView)
@State private var isPressed = false
GestureButton(
isPressed: $isPressed,
pressAction: { print("Pressed") },
releaseInsideAction: { print("Released inside") },
releaseOutsideAction: { print("Released outside") },
longPressDelay: 0.8,
longPressAction: { print("Long pressed") },
doubleTapAction: { print("Double tapped") },
repeatAction: { print("Repeat") },
label: { isPressed in
Text("Button")
.foregroundColor(isPressed ? .gray : .white)
.scaleEffect(isPressed ? 0.9 : 1.0)
}
)
// ScrollView gesture button (works inside ScrollView)
ScrollView {
LazyVStack {
ScrollViewGestureButton(
isPressed: $isPressed,
pressAction: { print("Pressed in scroll") },
releaseInsideAction: { print("Released") },
label: { isPressed in
Text("Scroll Button")
}
)
}
}
// Swipe gesture
.onSwipeGesture(
maximumTime: 1,
minimumDistance: 10,
up: { print("Swiped up") },
down: { print("Swiped down") },
left: { print("Swiped left") },
right: { print("Swiped right") }
)
// Gesture button defaults
GestureButtonDefaults.longPressDelay = 1.0
GestureButtonDefaults.doubleTapTimeout = 0.2
GestureButtonDefaults.repeatDelay = 1.0Core utility tools providing essential functionality for app development.
| Feature | Description | Usage |
|---|---|---|
| Brick | Core wrapper type Brick<Wrapped>, enables view.ss.xxx syntax |
view.ss.tabBar(.hidden) |
| SFSymbols | SF Symbol type-safe wrapper (V1-V7) | Image(systemName: SFSymbols.V1.heart) |
| Keyboard | Keyboard manager, track keyboard height | KeyboardManager.shared.keyboardHeight |
| Color+ | Color extensions: Hex init, dynamic colors, random colors | Color(hex: "#FF5733") |
| UIColor++ | UIColor extensions: Hex init, RGB init, dynamic colors | UIColor(hex: 0xFF5733) |
| UIView++ | UIView/NSView extensions: parentController, allSubviews() | view.allSubviews() |
| Screen++ | Screen utilities: safeArea, dimensions, device detection | Screen.width, Screen.safeArea |
| CGSize++ | CGSize extensions: greatestFiniteSize, min/max dimension | CGSize.greatestFiniteSize |
| Image+ | Image extensions: resize, tint, rotate, save to photos | image.resized(toWidth: 500) |
| Adapter | Responsive design adapter, zoom calculations | 100.zoom(), 10.screen.width(...) |
| CurrentLanguage | Current language detection | Brick.Language.currentLanguage |
| Application | App info: appName, version, buildNumber, appState | Brick.Application.appName |
| BrickLog | Logging: debug, info, warning, error, fault | Log.info("message") |
| ViewLifeCycle | View lifecycle: onFirstAppear, onDidDisappear, onWillDisappear | view.onFirstAppear { } |
// Static methods
Log.info("Info message")
Log.debug("Debug message")
Log.warning("Warning message")
Log.error("Error message")
Log.fault("Fault message")
// Instance methods
let logger = BrickLog.create(category: "MyLog")
logger.info("Custom log")
logger.error(.init("Error: \(error)"))// Hex initialization
Color(hex: 0xFF5733) // UInt64
Color(hex: "#FF5733") // String
Color.hex(0xFF5733) // Static method
// Dynamic colors (light/dark)
Color.dynamic(light: "#FFFFFF", dark: "#000000")
// Random colors
Color.random()
Color.random(in: 0.5...1.0, randomOpacity: true)@StateObject private var keyboardManager = KeyboardManager()
var body: some View {
VStack {
Text("Keyboard height: \(keyboardManager.keyboardHeight)")
}
.onAppear {
// Hide keyboard
KeyboardManager.hideKeyboard()
}
}// App information
Brick.Application.appName // App name
Brick.Application.appBundleID // Bundle ID
Brick.Application.versionNumber // Version (e.g. "1.0.0")
Brick.Application.buildNumber // Build number
Brick.Application.completeAppVersion // "1.0.0 (100)"
// App state
Brick.AppState.isDebug // Debug mode check
Brick.AppState.state // .debug / .testFlight / .appStorelet language = Brick.Language.currentLanguage // "en", "zh", etc.view.onFirstAppear {
print("First appeared!")
}
view.onWillDisappear {
print("Will disappear")
}
view.onDidDisappear {
print("Did disappear")
}// Screen dimensions
Screen.width
Screen.height
Screen.safeArea
Screen.scale
// Device detection
Device.isIpad // iPad check
Device.idiom // .pad / .phone / .tv
// Window/ViewController
UIWindow.keyWindow
UIViewController.currentViewController()
UIViewController.currentNavigationController()// Zoom calculation (responsive design)
let size = 100.zoom() // Auto scale based on screen width
let width = 375.zoom() // Convert from design width (375pt)
// Screen adaptation by width range
let value = 10.screen.width(0..<375, is: 10, zoomed: 8)
// Screen adaptation by screen inch
let height = 20.screen.inch(._6_1, is: 20, zoomed: 18)
// Screen adaptation by level (compact/regular/full)
let padding = 16.screen.level(.full, is: 20, zoomed: 16)
// Set custom zoom conversion
UIAdapter.Zoom.set { origin in
return origin * (UIScreen.main.bounds.width / 375.0)
}// Resize image
let resized = image.resized(toWidth: 500)
let byHeight = image.resized(toHeight: 300)
let maxWidth = image.resized(toMaxWidth: 200)
// Get JPEG data
if let jpgData = image.jpegData(resizedToWidth: 1000, withCompressionQuality: 0.8) {
// Use JPEG data
}
// Image format detection
let format = ImageFormat.get(from: data)
// iOS specific
image.copyToPasteboard() // Copy to clipboard
image.saveToPhotos { error in } // Save to album
// Tint color
let tinted = image.tinted(with: .red, blendMode: .sourceAtop)
// Rotate
let rotated = image.rotated(withRadians: .pi / 4)// Static methods
Log.info("Info message")
Log.debug("Debug message")
Log.warning("Warning message")
Log.error("Error message")
Log.fault("Fault message")
// Instance methods
let logger = BrickLog.create(category: "MyLog")
logger.info("Custom log")
logger.error("Error: \(error)")Starting from Xcode 11, the Swift Package Manager is integrated, which is very convenient to use. Brick_SwiftUI also supports integration via Swift Package Manager.
Select File > Swift Packages > Add Pacakage Dependency in Xcode's menu bar, and enter in the search bar
https://github.com/zjinhu/Brick_SwiftUI, you can complete the integration
Brick_SwiftUI also supports manual Install, just drag the Brick_SwiftUI folder in the Sources folder into the project that needs to be installed
zjinhu, 814030966@qq.com
Brick_SwiftUI is available under the MIT license. See the LICENSE file for more info.