Best Practices
Guidelines for effective code assistance and documentation usage in Alex Sidebar
Writing Effective Prompts
Clear Objectives
- Be specific about your goals
- State what you want to achieve
- Provide clear success criteria
Contextual Details
- Share relevant code snippets
- Include error messages
- Mention project requirements
Examples
❌ Ineffective: My code isn't working. Can you help?
✅ Effective: I'm getting a 'Thread 1: Fatal error: Unexpectedly found nil' when trying to unwrap an optional UIImage in my custom UICollectionViewCell. Here's my cellForItemAt implementation...
✅ Feature Request: I need to implement a custom tab bar in SwiftUI that shows a circular progress indicator around the selected tab icon. The progress should be animated. Here's my current TabView implementation...
Managing Context
File Context
- Use @ Files to add specific files
- Include related dependencies
- Share configuration files
Codebase Context
- Use @ Codebase for framework-level questions
- Reference specific components
- Share relevant modules
Examples
❌ Limited: How do I update this delegate method?
✅ Complete: I need to update this UITableViewDelegate method to handle custom swipe actions. Here's my current implementation (@Files TableViewController.swift) and the custom SwipeActionView (@Files Views/SwipeActionView.swift) I want to integrate.
✅ Framework: I'm building a custom networking layer (@Codebase Networking/*). Can you help me implement proper retry logic with exponential backoff?
Using Documentation
Apple Documentation
- Use @ Apple Docs for framework reference
- Reference specific APIs
- Include version information
Individual Docs
- Use @ Apple Docs (Individual) for specific methods
- Reference specific classes
- Include parameter details
Examples
❌ Vague: How do I use Core Data?
✅ Specific: I need help implementing NSFetchedResultsController (@Apple Docs NSFetchedResultsController) with multiple sections based on dates. Here's my current Core Data model (@Files Model.xcdatamodeld)...
✅ API Reference: Can you explain how to use URLSession's (@Apple Docs URLSession) background download tasks with proper delegate handling (@Apple Docs URLSessionDownloadDelegate)?
Platform-Specific Best Practices
Swift Best Practices
- Use Swift-specific terminology
- Reference Swift documentation
- Include Swift version
UIKit/AppKit
- Reference UI frameworks
- Include view hierarchy
- Share layout constraints
Examples
❌ Ambiguous: How do I create a button?
✅ SwiftUI: I'm using SwiftUI (iOS 16+) and need to create a custom button with a gradient background, dynamic shadow, and haptic feedback. Here's my current Button implementation...
✅ UIKit Integration: I need to embed this SwiftUI view (@Files CustomView.swift) into my existing UIKit navigation stack. Here's my current UIHostingController setup...
Common Scenarios
Debugging
- Share error messages
- Include stack traces
- Reference relevant code
Refactoring
- Explain current structure
- Describe desired outcome
- Share relevant files
Examples
❌ Unclear: The app crashes sometimes.
✅ Detailed: The app crashes when switching between tabs while a network request is in progress. Here's the crash log and relevant networking code (@Files NetworkManager.swift). The issue started after implementing async/await...
✅ Refactoring: I want to refactor this massive view controller (@Files ProfileViewController.swift) into smaller components using MVVM. Here's my planned architecture diagram...
Examples
❌ Too Much: Sharing entire project files for a simple UI fix
✅ Just Right: Continuing from our previous chat about the networking layer (see chat history), I need to add request caching. Here's the specific RequestCaching protocol I want to implement...
✅ Breaking Down: `I need to migrate this UIKit project to SwiftUI. Let’s break it down:
- First, let’s handle the navigation structure
- Then, convert each view controller individually
- Finally, implement the data flow with @StateObject and ObservableObject`
Community Resources
Need more help? Join the Discord community for support and tips from other developers.
Was this page helpful?