home / skills / rshankras / claude-code-apple-skills / generators

generators skill

/skills/generators

This skill generates production-ready Swift WidgetKit widgets with configurable sizes, types, and lock screen support to accelerate app enhancement.

npx playbooks add skill rshankras/claude-code-apple-skills --skill generators

Review the files below or copy the command above to add this skill to your agents.

Files (108)
SKILL.md
6.6 KB
# Widget Generator

Generate WidgetKit widgets for iOS/macOS home screen and lock screen.

## When to Use

- User wants to add widgets to their app
- User mentions WidgetKit or home screen widgets
- User wants lock screen widgets (iOS 16+)
- User asks about widget timelines or updates

## Pre-Generation Checks

```bash
# Check for existing widget extension
find . -name "*Widget*" -type d | head -5
grep -r "WidgetKit\|TimelineProvider" --include="*.swift" | head -5
```

## Configuration Questions

### 1. Widget Sizes
- **Small** - Compact info display
- **Medium** - More detail, horizontal
- **Large** - Full content area
- **All** - Support all sizes

### 2. Widget Type
- **Static** - Content updated on schedule
- **Interactive** (iOS 17+) - Buttons and toggles
- **Live Activity** (iOS 16+) - Real-time updates

### 3. Lock Screen Support (iOS 16+)
- **Yes** - accessoryCircular, accessoryRectangular, accessoryInline
- **No** - Home screen only

## Generated Files

```
WidgetExtension/
├── MyWidget.swift           # Widget definition
├── TimelineProvider.swift   # Timeline logic
├── WidgetViews.swift        # Size-specific views
└── Intent.swift             # Configuration intent (optional)
```

## Basic Widget Structure

```swift
import WidgetKit
import SwiftUI

struct MyWidget: Widget {
    let kind = "MyWidget"

    var body: some WidgetConfiguration {
        StaticConfiguration(
            kind: kind,
            provider: MyTimelineProvider()
        ) { entry in
            MyWidgetEntryView(entry: entry)
                .containerBackground(.fill.tertiary, for: .widget)
        }
        .configurationDisplayName("My Widget")
        .description("Shows important information.")
        .supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
    }
}
```

## Timeline Provider

```swift
struct MyTimelineProvider: TimelineProvider {
    func placeholder(in context: Context) -> MyEntry {
        MyEntry(date: .now, data: .placeholder)
    }

    func getSnapshot(in context: Context, completion: @escaping (MyEntry) -> Void) {
        let entry = MyEntry(date: .now, data: .snapshot)
        completion(entry)
    }

    func getTimeline(in context: Context, completion: @escaping (Timeline<MyEntry>) -> Void) {
        Task {
            let data = await fetchData()
            let entry = MyEntry(date: .now, data: data)
            let nextUpdate = Calendar.current.date(byAdding: .hour, value: 1, to: .now)!
            let timeline = Timeline(entries: [entry], policy: .after(nextUpdate))
            completion(timeline)
        }
    }
}
```

## Interactive Widgets (iOS 17+)

```swift
struct ToggleButton: View {
    var body: some View {
        Button(intent: ToggleIntent()) {
            Label("Toggle", systemImage: "checkmark.circle")
        }
    }
}

struct ToggleIntent: AppIntent {
    static var title: LocalizedStringResource = "Toggle Item"

    func perform() async throws -> some IntentResult {
        // Perform action
        return .result()
    }
}
```

## Lock Screen Widgets

```swift
.supportedFamilies([
    .accessoryCircular,
    .accessoryRectangular,
    .accessoryInline,
    .systemSmall,
    .systemMedium
])

struct AccessoryCircularView: View {
    var body: some View {
        Gauge(value: 0.75) {
            Text("75%")
        }
        .gaugeStyle(.accessoryCircularCapacity)
    }
}
```

## Integration Steps

1. File > New > Target > Widget Extension
2. Configure app groups for shared data
3. Implement TimelineProvider
4. Create size-specific views
5. Add widget to WidgetBundle

## Updating Widgets

```swift
import WidgetKit

// From main app
WidgetCenter.shared.reloadAllTimelines()

// Specific widget
WidgetCenter.shared.reloadTimelines(ofKind: "MyWidget")
```

## References

- [WidgetKit Documentation](https://developer.apple.com/documentation/widgetkit)
- [Creating a Widget Extension](https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension)

Overview

This skill generates production-ready Swift WidgetKit code for home screen and lock screen widgets. It produces a complete Widget Extension scaffold, timeline providers, size-specific SwiftUI views, and optional AppIntents for interactive widgets. Use it to add reliable, updatable, and platform-appropriate widgets to iOS and macOS apps.

How this skill works

The generator creates a Widget Extension folder with a widget definition, a TimelineProvider implementation, view files for each widget family, and an optional Intent or AppIntent file for configuration or interactivity. It wires timeline updates, snapshot and placeholder logic, and provides examples for reloads from the main app via WidgetCenter. It can configure supported families including home screen sizes and lock screen accessory types.

When to use it

  • You want to add home screen widgets to an existing iOS or macOS app.
  • You need lock screen widgets for iOS 16+ (accessoryCircular/Rectangular/Inline).
  • You want interactive widgets using AppIntents (iOS 17+) or Live Activities (iOS 16+).
  • You need a production-ready timeline provider with data fetching and scheduling.
  • You want scaffold code for size-specific SwiftUI views and widget configuration.

Best practices

  • Provide placeholder, snapshot, and timeline implementations to ensure smooth previews and timely updates.
  • Limit timeline update frequency; use policy like .after(nextUpdate) and sensible nextUpdate intervals.
  • Share data safely via App Groups when the widget and app need access to the same storage.
  • Support relevant widget families only; include lock screen types only when targeting iOS 16+.
  • Use AppIntents for interactive actions (iOS 17+) and keep intents lightweight and idempotent.

Example use cases

  • A news app that shows top headlines on the home screen with hourly timeline updates.
  • A fitness app that shows daily progress on a lock screen accessoryCircular gauge.
  • A to-do app with interactive toggle buttons to mark tasks complete (iOS 17+).
  • A finance app that fetches balances and updates the widget every 30–60 minutes.
  • An app that triggers WidgetCenter.shared.reloadTimelines(ofKind:) after significant data changes.

FAQ

Can I support lock screen widgets and home screen widgets together?

Yes. Include the appropriate supportedFamilies like accessoryCircular, accessoryRectangular, accessoryInline along with systemSmall/systemMedium/systemLarge and target iOS 16+.

How do I make widgets interactive?

Use AppIntents (iOS 17+) to define actions and Buttons bound to those intents. Keep actions fast and use background updates for state changes.