Expert guidance for iOS development using SwiftUI, MVVM+Coordinator architecture, Core Data persistence, and comprehensive testing patterns. Specialized for building feature-rich shopping apps with social features and gamification.
Expert guidance for iOS application development using SwiftUI, MVVM+Coordinator architecture pattern, Core Data persistence, and comprehensive testing strategies.
Provides step-by-step instructions for building and maintaining iOS applications following modern Swift development practices. Specializes in MVVM architecture with Coordinator pattern for navigation, Core Data for persistence, and comprehensive testing patterns including unit tests, view model tests, and UI automation.
When working with this codebase:
Before making database changes:
- Soft-delete via `isInShoppingList` boolean flag
- Multi-location pricing through `GroceryItemPrice` entities
- Flexible tagging system for organization
- Social graph via ShoppingExperience + UserComment relationships
Execute builds using provided scripts:
```bash
./rebuild_simulator.sh
xcodebuild -project CartWise.xcodeproj -scheme CartWise -destination "platform=iOS Simulator,name=iPhone 16" clean build
xcodebuild test -project CartWise.xcodeproj -scheme CartWise -destination "platform=iOS Simulator,name=iPhone 16"
```
In Xcode:
When implementing new functionality:
**A. Create/Update ViewModel**
**B. Create/Update Coordinator**
**C. Build SwiftUI Views**
**D. Update AppCoordinator**
When working with persistence:
**Creating Entities:**
```swift
let item = try await repository.createProduct(
productName: name,
brand: brand,
barcode: barcode,
category: category,
price: price,
location: location,
isOnSale: isOnSale,
addToShoppingList: addToList,
tags: selectedTags
)
```
**Querying Data:**
```swift
let products = try await repository.fetchAllProducts()
let listItems = try await repository.fetchListProducts()
let favorites = try await repository.fetchFavoriteProducts()
```
**Updating Entities:**
```swift
try await repository.updateProductWithPrice(
productId: item.id,
price: newPrice,
location: store,
username: currentUser
)
```
**Background Operations:**
```swift
try await CoreDataStack.shared.performBackgroundTask { context in
// Perform heavy operations on background context
let item = GroceryItem(context: context)
// ... configure entity
try context.save()
}
```
When adding API integrations:
Example:
```swift
let products = try await networkService.searchProductsOnMealMe(by: query)
if let imageURL = try await imageService.fetchImageURL(
for: productName,
brand: brand,
category: category
) {
// Cache URL in ProductImage entity
}
```
**Unit Tests** (`CartWiseTests/`):
**ViewModel Testing Pattern:**
```swift
@MainActor
func testProductViewModel() async throws {
let mockRepo = MockProductRepository()
let viewModel = ProductViewModel(repository: mockRepo)
await viewModel.fetchProducts()
XCTAssertEqual(viewModel.products.count, expectedCount)
}
```
**Core Data Testing:**
```swift
func testCoreDataStack() async throws {
let stack = CoreDataStack(inMemory: true)
// Perform operations on test stack
try await stack.save()
// Assert results
}
```
When working with user features:
When building community features:
**Memory Management:**
**Async/Await:**
**Error Handling:**
**SwiftUI State Management:**
**Navigation:**
```swift
// 1. Update ViewModel
@MainActor
class ProductViewModel: ObservableObject {
@Published var featuredProducts: [GroceryItem] = []
func fetchFeaturedProducts() async {
do {
featuredProducts = try await repository.fetchFeaturedProducts()
} catch {
print("Error fetching featured: \(error)")
}
}
}
// 2. Update Coordinator
@MainActor
class ShoppingListCoordinator: ObservableObject {
@Published var showingFeaturedModal = false
func showFeaturedProducts() {
showingFeaturedModal = true
}
}
// 3. Update View
struct YourListView: View {
@ObservedObject var viewModel: ProductViewModel
@ObservedObject var coordinator: ShoppingListCoordinator
var body: some View {
Button("Featured") {
coordinator.showFeaturedProducts()
}
.sheet(isPresented: $coordinator.showingFeaturedModal) {
FeaturedProductsView(products: viewModel.featuredProducts)
}
}
}
```
```swift
func fetchProductsByCategory(_ category: ProductCategory) async throws -> [GroceryItem] {
try await CoreDataStack.shared.performBackgroundTask { context in
let request = GroceryItem.fetchRequest()
request.predicate = NSPredicate(format: "category == %@", category.rawValue)
request.sortDescriptors = [NSSortDescriptor(key: "productName", ascending: true)]
return try context.fetch(request)
}
}
```
```swift
func fetchWithRetry<T>(operation: () async throws -> T) async throws -> T {
var lastError: Error?
for attempt in 0..<3 {
do {
return try await operation()
} catch {
lastError = error
let delay = UInt64(pow(2.0, Double(attempt)) * 1_000_000_000) // Exponential backoff
try await Task.sleep(nanoseconds: delay)
}
}
throw lastError ?? NetworkError.maxRetriesExceeded
}
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/ios-swiftui-mvvm-development-assistant/raw