Xcode Previews

RSS for tag

Create an app UI and configure almost everything your users see using Xcode Previews.

Posts under Xcode Previews tag

153 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Xcode error at preview after changing my macOS user account name
Hello, Today earlier I changed my macOS user account name and now I'm getting error at Xcode 16 at Preview. A piece of error report is: XOJITError: Could not create oop-jit code file directory /Users/victorvaz/Library/Developer/Xcode/UserData/Previews/Simulator Devices/CCCD8E24-3E82-4B02-9D30-0E2B5D09EB4A/data/Containers/Data/Application/D4EA132D-A318-4D58-8618-DFD428FD5F71/tmp/OOPJit/previews: Permission denied But "victorvaz" is my old macOS user account name, how can I make Xcode identify my new account name? Kind regards, Victor de Oliveira
2
0
217
4w
Can I preview "regular" view in widget extension?
Basically, in my widget/live activity, I want to extract reusable views into a separate file with an isolated view and preview. Dummy example below. I cannot do it because it says "missing previewcontext". The only way I've found is to add the view to my main app target, but I don't want to clutter my main app wiews that only exist in my widgets if I can avoid it. Can this be done somehow? Thoughts appreciated. Dummy example (tried with and without "previewLayout": struct StatusActivityView: View { let status: UserStatusData var body: some View { VStack(alignment: .center) { Text("Dummy example") }.background(.blue).padding(5) } } @available(iOS 16.2, *) struct StatusActivityView_Previews: PreviewProvider { static var previews: some View { let status = WidgetConstants.defaultEntry() return StatusActivityView(status: status).previewLayout(.sizeThatFits) } }
2
0
235
4w
SampleTrips Previews work, but not in my primary project.
I wanted to get my SwiftData previews working in my primary project, so I started modeling them after the SampleTrips project. After messing around with that & being unable to make it work, I brought the same (working) sample code into my main project, unfortunately that's not working... I've attached the preview error (note, there's nothing in the Diagnostic Reports). //Sample code that works in it's own project, but not my primary target. import SwiftUI import SwiftData struct TestSwiftDataStuffView: View { let trip: Trip var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, \(trip.name)!") .padding() .foregroundColor(.red) } .padding() } } #Preview(traits: .sampleDataSecondary) { @Previewable @Query var trips: [Trip] TestSwiftDataStuffView(trip: trips.first!) } actor DataModelSecondary { struct TransactionAuthor { static let widget = "widget" } static let shared = DataModelSecondary() private init() {} nonisolated lazy var modelContainer: ModelContainer = { let modelContainer: ModelContainer let schema = Schema([ Trip.self ]) do { let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false, cloudKitDatabase: .none) modelContainer = try ModelContainer(for: schema, configurations: [modelConfiguration]) } catch { fatalError("Failed to create the model container: \(error)") } return modelContainer }() } @Model class Trip { @Attribute(.preserveValueOnDeletion) var name: String init(name: String) { self.name = name } } extension Trip { static var previewTrips: [Trip] { [ Trip(name: "Revenant"), Trip(name: "Newcastle"), Trip(name: "Bianca") ] } } struct SampleDataSecondary: PreviewModifier { static func makeSharedContext() throws -> ModelContainer { let config = ModelConfiguration(isStoredInMemoryOnly: true) let container = try ModelContainer( for: Trip.self, configurations: config ) SampleDataSecondary.createSampleData(into: container.mainContext) return container } func body(content: Content, context: ModelContainer) -> some View { content.modelContainer(context) } static func createSampleData(into modelContext: ModelContext) { Task { @MainActor in let sampleDataTrips: [Trip] = Trip.previewTrips let sampleData: [any PersistentModel] = sampleDataTrips //+ sampleDataLA + sampleDataBLT sampleData.forEach { modelContext.insert($0) } try? modelContext.save() } } } @available(iOS 18.0, *) extension PreviewTrait where T == Preview.ViewTraits { @MainActor static var sampleDataSecondary: Self = .modifier(SampleDataSecondary()) } Xcode16Preview.txt
3
0
431
3w
SwiftUI Previews not working with Firebase in Xcode 16.0 beta
The SwiftUI previews have been working fine in Xcode 16.0 beta, but ever since I added Firebase into my app, I've been getting error with previews. CrashReportError: IshaanCord crashed IshaanCord crashed. Check ~/Library/Logs/DiagnosticReports for crash logs from your application. Process: IshaanCord[5651] Date/Time: 2024-07-04 19:29:51 +0000 Log File: <none> "Cannot preview in this file" Does anyone know how to fix this? Thank you.
2
0
289
2w
ContentView
Hello, I‘ve started developing an App not to long ago on Xcode and I have noticed that I can’t see any progress or like preview of what I have coded so far and it’s starting to concern me. I have Xcode version 15.5 and I am coding with swift, everything works fine there is no error or anything preventing it to run but when I try to preview the only thing I see when I launch the Simulator and I open my app the only thing I see is a white page. Can someone please help me.
2
0
213
3w
SwiftUI Preview + Swift Packages Break App
I have a multi-platform app with the SwiftUI code a separate Swift Package. Any Views with SwiftUI Previews break the compilation of the app. Here's the error message I get in Xcode: Showing All Messages ld: warning: Could not parse or use implicit file '/Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore.tbd': cannot link directly with 'SwiftUICore' because product being built is not an allowed client of it Undefined symbols for architecture arm64_32: "(extension in SwiftUI):DeveloperToolsSupport.Preview.init(_: Swift.String?, traits: DeveloperToolsSupport.PreviewTrait&lt;DeveloperToolsSupport.Preview.ViewTraits&gt;..., body: @Swift.MainActor @Sendable () -&gt; SwiftUI.View) -&gt; DeveloperToolsSupport.Preview", referenced from: static BitnessViews.$s12BitnessViews33_ABDBADF565C741E50A2A5746CE94FCD9Ll7PreviewfMf_15PreviewRegistryfMu_.makePreview() throws -&gt; DeveloperToolsSupport.Preview in BitnessViews.o ld: symbol(s) not found for architecture arm64_32 clang: error: linker command failed with exit code 1 (use -v to see invocation) Could not parse or use implicit file '/Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore.tbd': cannot link directly with 'SwiftUICore' because product being built is not an allowed client of it Undefined symbol: (extension in SwiftUI):DeveloperToolsSupport.Preview.init(_: Swift.String?, traits: DeveloperToolsSupport.PreviewTrait&lt;DeveloperToolsSupport.Preview.ViewTraits&gt;..., body: @Swift.MainActor @Sendable () -&gt; SwiftUI.View) -&gt; DeveloperToolsSupport.Preview Linker command failed with exit code 1 (use -v to see invocation) Any thoughts as to what might be going on here?
1
0
256
3w
Xcode 16 Previews: dyld Loader Crash
We have been seeing a dyld loader crash when trying out the new Previews engine in Xcode 16 beta 3. Feedback filed with reproducer + diagnostics: https://feedbackassistant.apple.com/feedback/14323960 Investigation: Running nm -a on the debug dylib reveals duplicate SO entries pointing to SomeStatic.swift. One entry originates from the LibAStatic module, while the other comes from the LibBStatic module. Local workaround - 1 Providing unique file names resolves the issue. However, these files are in different modules, so ideally, this shouldn't be necessary. Our codebase is extensive, and many code-generated modules have the same file names. Therefore, renaming files to ensure uniqueness is not a simple solution for us due to various complexities. Local workaround - 2 Making these dependencies dylibs instead of static libraries also resolves the issue. However, we can't pursue this direction because a significant portion of our pre-build setup, foundations, and vendor linkages are statically linked. Note: The same flow works with "Legacy Preview Engine in Xcode 16/15" but dynamic replacement has other issues, which we are super happy that the new engine doesn't make use of. This issue is currently a blocker for us in trying out the new Previews in our project, it would be highly beneficial if this problem could be resolved soon.
1
0
212
1w
Xcode 16 Previews: Always crash when compilation mode is WMO
This can be easily reproduced in a vanilla Xcode 16 beta 3 project. Steps Create a new project. By default, previews work fine because default SWIFT_COMPILATION_MODE is Incremental. (aka Batch Mode) Now, change it to WMO, and notice the previews crash with the enclosed crash report. Feedback filed with reproducer + diagnostics + crash report: https://feedbackassistant.apple.com/feedback/14268698 We have observed that enabling Whole Module Optimization (WMO) improves build times in our project. Therefore, if Previews can be compatible with WMO, it would be highly beneficial. Otherwise, it would be helpful to provide a warning or feedback to developers, as many projects are likely utilizing WMO, and identifying issues solely from crash reports can be challenging. Note: This works all fine with the Legacy Previews Engine in Xcode 15/16.
1
0
165
1w
How to change the background color of the status bar in SwiftUI when creating a custom NavigationController View
I wanted to experiment a little using UINavigationController with SwiftUI App Lifecycle I created a Custom Navigation Controller named JDNavigationController. It does not do much other than having the @Observable macro public struct NavigationControllerStack<Content: View>: UIViewControllerRepresentable { private let initialView: () -> Content @State private var controller = JDNavigationController() public init(content: @escaping () -> Content) { self.initialView = content } public func makeUIViewController(context: Context) -> JDNavigationController { let viewController = self.initialView() .environment(self.controller) .viewController self.controller.viewControllers = [ viewController ] return controller } public func updateUIViewController(_ uiViewController: JDNavigationController, context: Context) { } public typealias UIViewControllerType = JDNavigationController } when I check, the functionality of the navigation controller works as expected, however, I can't for the life of me to change the background color of the status bar. #Preview { NavigationControllerStack { ZStack { Color.purple .ignoresSafeArea(.all) VStack { Text("somethign") } } } } I have tried Using the appearance functions Creating a Custom View Controller, and in that view controller I tried using a Hosting Controller by adding the hosting controller as a child and setting hostingController.view.insetsLayoutMarginsFromSafeArea = false using the toolbar modifiers from SwiftUI View none seems to work. I opened the View Debugger it looks like the white portion comes from the UIHosting Controller but I am not sure what I can do to fix it
6
0
213
3d
SwiftUI preview with different @AppStorage values
I have SwiftUI views, which access the user defaults by using the property wrapper @AppStorage. Now I would like to have a preview with multiple variations of the view depending on the same user default with different values. Is there a pure way to do that? Currently I have a solution which is very probably a hack and supports only one variation of the user default. To do that I define the user settings in a sub views onAppear() method: struct MyTestedView_Previews : PreviewProvider { static var previews: some View { VStack { VStack { MyTestedView .previewLayout(.sizeThatFits) } .onAppear{ UserDefaults.standard.set(true, forKey: "myConsumedKey") } //VStack //{ // MyTestedView // .previewLayout(.sizeThatFits) //} //.onAppear{ // UserDefaults.standard.set(false, forKey: "myConsumedKey") //} } } } When I have two VStack for different variations and I set the user defaults to different values in their onAppear(), only one user default value wins and I see one variation of my view twice. What I also don't like on my solution, is that I don't know where this user default is stored. Is it stored temporary in the memory or do I even manipulate Xcode's user defaults? Does anybody know if SwiftUI has already a solution to test different variations of user defaults in the preview?
2
0
122
4d