I receive the following compiler error:
Cannot infer key path from context; consider explicitly specifying a root type
when I attempt an @Environment(\.foodRepository) lookup in a descendant View.
Here's the setup in my App class:
import SwiftUI
import SwiftData
@main
struct BulkCutApp: App {
private var foodRepository: FoodRepository = /* some code*/
var body: some Scene {
WindowGroup {
ContentView()
.foodRepository(foodRepository)
}
}
}
extension View {
func foodRepository(_ customValue: FoodRepository) -> some View {
environment(\.foodRepository, customValue)
}
}
extension EnvironmentValues {
var foodRepository: FoodRepository {
get { self[FoodRepositoryKey.self] }
set { self[FoodRepositoryKey.self] = newValue }
}
}
struct FoodRepositoryKey: EnvironmentKey {
static var defaultValue: FoodRepository = FoodRepository(food:[])
}
Nothing special in FoodRepository:
@Observable
class FoodRepository {
var food: [Food]
// more code
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am attempting to generate screenshots at various logical times using a watchOS 11 simulator.
% xcrun simctl status_bar "Apple Watch Series 10 (46mm)" override --time 9:06
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=45):
Simulator device failed to complete the requested operation.
Operation not supported
Underlying error (domain=NSPOSIXErrorDomain, code=45):
Status bar overrides not supported on this platform.
Operation not supported
Using WatchOS Clock Settings gives me at most 59 minutes in which to succeed.
Even if I had a physical watch for every series and size, I would have to wait up to 23 hours before being able to generate my marketing screenshots to support various user scenarios. With three settings variations, a minimal wait time to get to good marketable content would be on the order of 1 month per app version.
Topic:
Developer Tools & Services
SubTopic:
Xcode