25 Prompts for Swift and iOS: SwiftUI, UIKit, Core Data, and Combine

Introduction

As an iOS developer, you know that crafting clean Swift code, designing responsive SwiftUI layouts, and managing data with Core Data can be time-consuming. The AI coding assistants of 2026—like GitHub Copilot, Claude, and local LLMs—are powerful, but only if you feed them the right prompts. This article shares 25 battle-tested prompts that I actually use in my daily workflow. Each prompt is specific, actionable, and designed to save you hours. Whether you're building a new feature or debugging a Core Data migration, these prompts will help you get the job done faster.

SwiftUI Prompts

1. Generate a Custom View with State Management

  • Prompt: "Create a SwiftUI view that displays a list of items with a search bar. Use @State for the search text and @ObservedObject for the data model. Include a pull-to-refresh action that loads new data from an async function."
  • Why it works: It specifies state management, data flow, and async behavior—avoiding vague responses.
  • Example use case: Building a notes app with real-time search.

2. Build a Responsive Grid Layout

  • Prompt: "Write a SwiftUI grid layout that adapts from 2 columns on iPhone to 4 columns on iPad. Use LazyVGrid with adaptive grid items. Each cell should show an image and a title, with a tap gesture that opens a detail view."
  • Why it works: It forces the AI to handle device-specific layouts and navigation.

3. Add Accessibility to an Existing View

  • Prompt: "Add VoiceOver support to this SwiftUI view: [paste code]. Include accessibility labels, hints, and traits for all interactive elements. Use accessibilityChildren for grouped controls."
  • Why it works: Accessibility is often overlooked; this prompt produces production-ready code.

4. Create a Custom Animation

  • Prompt: "Implement a spring animation in SwiftUI for a card flip effect. The card should rotate 180 degrees on tap, with a 0.5-second spring response and 0.3 damping. Use .rotation3DEffect and withAnimation."
  • Why it works: Parameters like response and damping prevent generic animation code.

5. Convert UIKit Code to SwiftUI

  • Prompt: "Convert this UIKit table view with a custom cell [paste code] to a SwiftUI List with a custom row view. Preserve the delegate methods for row selection and swipe actions."
  • Why it works: Bridges the gap for developers migrating from UIKit.

UIKit Prompts

6. Implement Auto Layout Programmatically

  • Prompt: "Write a UIView subclass with two labels aligned vertically. Use NSLayoutConstraint anchors to pin the first label to the top and the second label 10 points below it. Add a 16-point horizontal margin from the superview."
  • Why it works: Avoids ambiguous constraints by specifying exact spacing and anchors.

7. Build a Custom Navigation Controller

  • Prompt: "Create a UINavigationController subclass that hides the default navigation bar and uses a custom UIView as the title view. Add a back button with a custom image and a right bar button item with an action."
  • Why it works: Custom navigation is common but tedious; this prompt delivers a complete solution.

8. Handle Keyboard Notifications

  • Prompt: "Write a UIViewController extension that observes UIResponder.keyboardWillShowNotification and keyboardWillHideNotification. Adjust the view’s bottom constraint to move the content above the keyboard. Include animation with the keyboard’s animation curve."
  • Why it works: Keyboard handling is a classic pain point; the prompt ensures proper animation and constraint updates.

9. Create a Custom Collection View Layout

  • Prompt: "Implement a UICollectionViewFlowLayout subclass that creates a Pinterest-style masonry layout. Each item’s height should be proportional to its width, with a random height variation between 100 and 200 points. Use prepare() to precompute layout attributes."
  • Why it works: Specifies layout type and height logic, reducing back-and-forth.

10. Add Dark Mode Support

  • Prompt: "Refactor this UIViewController [paste code] to support dark mode. Use UIColor.systemBackground for views, UIColor.label for text, and UIImage with alwaysOriginal rendering mode. Test with traitCollectionDidChange."
  • Why it works: Dark mode requires careful color management; this prompt covers all bases.

Core Data Prompts

11. Set Up a Core Data Stack

  • Prompt: "Generate a Core Data stack using NSPersistentContainer for a model named 'DataModel'. Include a shared singleton with a viewContext, backgroundContext, and a save method that merges changes from both contexts. Use lazy initialization."
  • Why it works: A singleton stack is a standard pattern; the prompt ensures thread safety.

12. Write a Fetch Request with Predicates

  • Prompt: "Create a fetch request for an entity called 'Task' with attributes: title (String), dueDate (Date), isCompleted (Bool). Filter for tasks where isCompleted is false AND dueDate is before today. Sort by dueDate ascending. Use NSPredicate with format and NSFetchRequest."
  • Why it works: Complex predicates are error-prone; this prompt generates correct syntax.

13. Perform a Batch Update

  • Prompt: "Write a batch update using NSBatchUpdateRequest to set isCompleted to true for all tasks with dueDate before yesterday. Execute on a private context and refresh the view context afterward. Print the number of updated objects."
  • Why it works: Batch updates are efficient but tricky; the prompt includes result handling.

14. Handle Lightweight Migration

  • Prompt: "Add automatic lightweight migration to a Core Data stack. Set shouldMigrateAutomatically and shouldInferMappingModelAutomatically to true. Handle migration errors with a do-catch block and print the error description."
  • Why it works: Migration failures crash apps; this prompt adds proper error handling.

15. Implement a FetchedResultsController

  • Prompt: "Create an NSFetchedResultsController for the Task entity with sectionNameKeyPath based on a 'category' attribute. Use a delegate to update a UICollectionView when data changes. Include performFetch in viewDidLoad."
  • Why it works: FetchedResultsController is powerful but verbose; the prompt covers setup and delegation.

Combine Prompts

16. Create a Network Publisher

  • Prompt: "Write a Combine publisher that fetches JSON from a URL using URLSession.dataTaskPublisher. Decode the response into a Codable array of User objects. Handle errors by mapping them to a custom NetworkError enum. Use receive(on: DispatchQueue.main) for UI updates."
  • Why it works: Combine networking is common; the prompt ensures proper threading and error handling.

17. Debounce a Search Text Field

  • Prompt: "Create a Combine pipeline that observes a UITextField’s text changes. Apply a debounce of 0.5 seconds, remove duplicates, then call an async search function. Cancel the previous request if a new one comes in. Use flatMap with maxPublishers: .max(1)."
  • Why it works: Debouncing prevents excessive API calls; flatMap handles request cancellation.

18. Merge Multiple Publishers

  • Prompt: "Merge two Combine publishers: one that emits a user’s profile from a database, and another that emits their recent posts from a network. Use combineLatest to produce a tuple (profile, posts) and update a SwiftUI view. Handle both success and failure."
  • Why it works: CombineLatest is ideal for dependent data; the prompt avoids race conditions.

19. Implement a Custom Subject

  • Prompt: "Create a PassthroughSubject that emits Int values. Subscribe to it with a sink that prints values. Also create a CurrentValueSubject with an initial value of 0, and subscribe to it. Show how to send values through both subjects."
  • Why it works: Understanding subjects is key to mastering Combine.

20. Use Timers with Combine

  • Prompt: "Write a Combine timer that fires every 1 second on the main thread. Use the autoconnect() method to start immediately. The sink should update a SwiftUI Text view with the current time formatted as HH:mm:ss. Dispose of the subscription with a Set."
  • Why it works: Timers are common for live updates; autoconnect() simplifies lifecycle.

General Swift Prompts

21. Write a Protocol with Associated Types

  • Prompt: "Define a protocol 'Cacheable' with an associated type 'Item'. Require a function save(_ item: Item) and load() -> Item?. Implement a concrete class 'UserCache' that conforms to Cacheable with Item = User. Use NSCache internally."
  • Why it works: Generics and protocols are hard; this prompt provides a working pattern.

22. Implement a Singleton with Thread Safety

  • Prompt: "Create a thread-safe singleton class 'Logger' that writes messages to a file. Use a serial DispatchQueue for write operations and a concurrent queue with barrier for reads. Include a method log(_ message: String) that timestamps each entry."
  • Why it works: Thread-safe singletons are essential; the prompt prevents data races.

23. Refactor Code with Async/Await

  • Prompt: "Convert this completion-handler-based network call [paste code] to use Swift’s async/await. Use URLSession’s async data method. Handle errors with do-catch and return a Result type. Call it from a SwiftUI task modifier."
  • Why it works: Modernizes legacy code with Swift concurrency.

24. Write Unit Tests for a ViewModel

  • Prompt: "Create XCTest unit tests for a SwiftUI ViewModel that has a published property 'items' and a method 'loadItems()' that fetches data. Mock the network service using a protocol. Test success, failure, and loading states. Use XCTestExpectation for async tests."
  • Why it works: Testing ViewModels ensures UI reliability; mocking is built into the prompt.

25. Generate Documentation with DocC

  • Prompt: "Add DocC documentation comments to this Swift function [paste code]. Include a summary, parameter descriptions, a return value description, and a code example in a Discussion section. Use the recommended syntax for Xcode 16."
  • Why it works: Well-documented code is easier to maintain; the prompt follows Apple’s standards.

Conclusion

These 25 prompts cover the most common iOS development scenarios—from SwiftUI layouts to Core Data migrations. The key is to be specific: include data types, framework names, and desired behaviors. Avoid vague requests like "make a list"—instead, say "create a SwiftUI List with 3 columns and pull-to-refresh." In 2026, AI is a powerful pair programmer, but your prompts determine the quality of its output. Bookmark this list, and you’ll save hours every week. Happy coding!

← All posts

Comments