Xcode Previews

RSS for tag

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

Posts under Xcode Previews tag

158 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Xcode previews fail with JIT error
== PREVIEW UPDATE ERROR: JITError ================================== | NoBuiltTargetDescriptionCouldBeFound | | translationUnit: PreviewTranslationUnit(moduleNamePrefix: "Previews_EmptyFeedRow", sourceIdentifier: file:///Users/bryananderson/Developer/JournalApp/JournalApp/Interface/Feed/EmptyFeedRow.swift -> EmptyFeedRow.swift, parseTree: ParseTree(version: 727, statements: 3, providers: 1), update: nil, changesContextMemoizer: PreviewsPipeline.PreviewTranslationUnit.(unknown context at $34b4b9c4c).ChangesContextMemoizer(parseTree: ParseTree(version: 727, statements: 3, providers: 1), sourceIdentifier: file:///Users/bryananderson/Developer/JournalApp/JournalApp/Interface/Feed/EmptyFeedRow.swift -> EmptyFeedRow.swift, cachedValue: os.OSAllocatedUnfairLock<Swift.Optional<PreviewsModel.ParseTree.PreviewChangesContext>>(__lock: Swift.ManagedBuffer<Swift.Optional<PreviewsModel.ParseTree.PreviewChangesContext>, __C.os_unfair_lock_s>)), registryDeclarationMemoizer: PreviewsPipeline.PreviewTranslationUnit.(unknown context at $34b4b9bec).RegistryDeclarationMemoizer) | | builtTargetDescriptions: | == VERSION INFO: Tools: 16A5171c OS: 24A5264n PID: 906 Model: MacBook Pro Arch: arm64e == ENVIRONMENT: openFiles = [ /Users/bryananderson/Developer/JournalApp/JournalApp/Interface/Feed/EmptyFeedRow.swift ] wantsNewBuildSystem = true newBuildSystemAvailable = true activeScheme = JournalApp activeRunDestination = iPhone 15 Pro variant iphonesimulator arm64 workspaceArena = [x] buildArena = [x] buildableEntries = [ Remember.app ] runMode = JIT Executor == SELECTED RUN DESTINATION: name = iPhone 15 Pro eligible = true sdk = Optional(<DVTSDK:0x13870da30:'iphonesimulator18.0':Simulator - iOS 18.0:<DVTFilePath:0x600001e8c700:'/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.0.sdk'>>) variant = Optional("iphonesimulator") device = Optional(<DVTiPhoneSimulator: 0x32f00d290> { SimDevice: iPhone 15 Pro (CF3C85BC-F559-4437-9072-7F30153B399B, iOS 18.0, Booted) PairedSim: <DVTiPhoneSimulator: 0x33733d150> { SimDevice: Apple Watch Series 9 (45mm) (627CE93E-EB02-4200-BE40-3DCB5C91DB44, watchOS 11.0, Shutdown) } }) == SELECTED RUN DESTINATION: Simulator - iOS 18.0 | iphonesimulator | arm64 | iPhone 15 Pro | Apple Watch Series 9 (45mm) jit enabled: true fallback to dynamic replacement: false
2
1
114
6d
SwiftData with CloudKit freezing previews in Xcode 16 beta
To reproduce: In Xcode, create a new project with SwiftData storage Add a new item in the preview — everything works fine so far Enable CloudKit sync for the target (add iCloud capability, check CloudKit, add a container) Go back to the preview and add a new item — Xcode will now freeze As soon as you modify the SwiftData storage, the preview freezes and the Xcode app becomes extremely slow until you either refresh the preview or restart Xcode.
0
0
68
6d
@Previewable version problem iOS 18 - 17
Hi, i am currently updating my app in SwiftUI from iOS 16.4 to 18.0, i am getting in xcode these new warning @State' used inline will not work unless tagged with '@Previewable' so i fix the problem with the suggestions and add the new tag @Previewable and put the variable in the first line of the preview #Preview { @Previewable @State var enabled: Bool = true return NotificationLabel(enabled: $enabled, type: "test", icon: "star", title: "test", description: "test") } the problem is that my app is available from iOS 16.4 to iOS 18.0 and the preview gives me this error 'Previewable()' is only available in iOS 18.0 or newer but if i put a versione if at the top i get another error if #available(iOS 18.0, *){ @Previewable @State var enabled: Bool = true @Previewable' items must be at root scope in the preview block is there a way to silence the warning making a two version preview, one for iOS 18 and one for the previous versions?
1
0
170
1w
Crowdstrike Falcon vs Xcode build performance
Crowdstrike Falcon vs Xcode performance Our IT department is using CrowdStrike Falcon, an ML-security tool, on all the Mac hardware. It will flag processes as malicious, and it sounds like it may sandbox such processes that are deemed malicious and / or scan anything the process touches. TLDR Does anybody know how to make CrowdStrike Falcon behave nicely with Xcode and its tools and prevent it from consuming high CPU and interfering with the build and debugging processes? Xcode, SwiftUI previews and building should be as performant as possible. Details Perplexity describes CrowdStrike Falcon as follows: CrowdStrike Falcon is a cloud-based endpoint security platform that provides real-time protection against malware, ransomware, and other cyber threats. It uses artificial intelligence and machine learning to detect and prevent known and unknown threats across endpoints (laptops, desktops, servers, etc.), cloud workloads, and cloud environments. The Falcon platform includes next-generation antivirus, endpoint detection and response (EDR), managed threat hunting, vulnerability management, and other security capabilities delivered through a lightweight sensor that streams data to the CrowdStrike cloud for analysis and response. The problem is that apparently Falcon's ML signatures will flag Xcode as malicious. So when building in Xcode, Falcon will use a huge amount of CPU (I have seen it go up to 456%), affecting build performance. I am getting the impression it is sandboxing and / or scanning every single file Xcode touches. The same goes for the iOS Simulator which will also cause Falcon to consume lots of CPU. It's clear this is affecting our build performance a lot. Falcon supports a number of exclusions: Machine learning (ML) exclusion: For trusted file paths, stop all ML-based detections and preventions, or stop files from being uploaded to the CrowdStrike cloud. Indicator of attack (IOA) exclusion: Stop all behavioral detections and preventions for an IOA that’s based on a CrowdStrike-generated detection. Sensor visibility exclusion: For trusted file paths that you want to exclude from sensor monitoring, minimize sensor event collection, and stop all associated detections and preventions. Use sensor visibility exclusions with extreme caution. Potential attacks and malware associated with excluded files will not be recorded, detected, or prevented. Using Sensor Visibility Exclusions it is possible to exclude applications on file pattern basis and preventing Falcon's ML signatures for flagging any such process as malicious. Which means that it is possible to exclude /Applications/Xcode.app/** and prevent it, or the processes it spawns, as malicious. However, Xcode and the toolchain are much more complicated than just excluding a single binary. Switching toolchains via sudo xcode-select -s will also update a lot of files in /usr (see Xcode.app/Contents/Developer/usr) such as /usr/bin/swift*, /usr/bin/ibtool*, /usr/bin/lldb and /usr/bin/xcrun (there are many more). For testing Xcode performance we excluded /Applications/Xcode.app/** and /usr/bin from Falcon, but just launching the simulator and a simulator build of the app will still cause Falcon to go up to about 300%. I assume this will affect SwiftUI live previews as well. Probably /Users/*/Library/Developer/** should be excluded as well then? Obviously, Falcon's AI/ML should just identify all of this as legitimate software development tools and no exclusions should be necessary... IMHO a file-pattern based exclusion seems to contradict what this tool is supposed to do. I would think it should evaluate signing (codesign / spctl) or validate checksums, rather than file pattern based exclusions. But as long as Xcode becomes more performant I am not complaining. The less an IT tool is flagging legitimate software as malicious and interfering with our daily work, the better. So my question is if anybody knows how to make CrowdStrike Falcon behave nicely with Xcode and its tools and prevent it from consuming high CPU and interfering with the build and debugging processes? Xcode, SwiftUI previews and building should be as performant as possible.
0
2
226
1w
SwiftUI Previews broken on local Swift Package with dependencies
I have a project with two local packages One client package with an interface and some models with dynamic type in the Package.Swift One feature package with the UI and a dependency to the client package When I try to preview a view that is not using any models or code from the client package, it loads just fine e.g. a view that is just a container to display things like a card But when I tried to preview any other view that actually uses models from the client package, it just fails the first few lines of the preview error display LinkDylibError: Failed to build <filename>.swift Linking failed: linker command failed with exit code 1 (use -v to see invocation) ld: warning: search path '/Applications/Xcode-15.4.0.app/Contents/SharedFrameworks-iphonesimulator' not found Undefined symbols for architecture arm64: Also, I'm using Xcode 15.4 and iOS 17 as the min version
1
1
112
1w
Previewing your app’s interface in Xcode
// // ContentView.swift // HardApp // // Created by Besleaga Alexandru Marian on 14.06.2024. // import SwiftUI struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("Hello, world!") } .padding() } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } // A SwiftUI preview. #Preview { Use of unknown directive '#Preview' // The view to preview. } I'm trying to learn Xcode and got stuck on these error that I receive when trying to apply the macro #Preview, how can declare the directive so I can use it in my own code for the preview it offers ? Kind Regards
1
0
107
1w
PREVIEW UPDATE ERROR: LinkDylibError
Hey Guys, a have some problens with Xcode preview for some reason I'm getting this error LinkDylibError: Failed to build CardDetailsScreen.swift Linking failed: linker command failed with exit code 1 (use -v to see invocation) ld: -make_mergeable can only be used when creating a dynamic library clang: error: linker command failed with exit code 1 (use -v to see invocation) previews_diagnostics_summary.txt
1
1
114
1w
"TranslationUnit" - Xcode Previews constantly crash in Xcode 16 Beta 1
Hey, I've opened an existing project with Xcode 16 Beta 1 (I'm also running macOS Sequoia). None of my previews work anymore. They simply crash with an error I don't quite understand: JITError ================================== | NoBuiltTargetDescriptionCouldBeFound | | translationUnit: PreviewTranslationUnit(moduleNamePrefix: "Previews_ErrorView", sourceIdentifier: file:///Users/dennis/Code/Project/Project/Components/ErrorView.swift -> ErrorView.swift, parseTree: ParseTree(version: 1848, statements: 5, providers: 0), update: nil, changesContextMemoizer: PreviewsPipeline.PreviewTranslationUnit.(unknown context at $3561fdc4c).ChangesContextMemoizer(parseTree: ParseTree(version: 1848, statements: 5, providers: 0), sourceIdentifier: file:///Users/dennis/Code/Project/Project/Components/ErrorView.swift -> ErrorView.swift, cachedValue: os.OSAllocatedUnfairLock<Swift.Optional<PreviewsModel.ParseTree.PreviewChangesContext>>(__lock: Swift.ManagedBuffer<Swift.Optional<PreviewsModel.ParseTree.PreviewChangesContext>, __C.os_unfair_lock_s>)), registryDeclarationMemoizer: PreviewsPipeline.PreviewTranslationUnit.(unknown context at $3561fdbec).RegistryDeclarationMemoizer) | | builtTargetDescriptions: The app builds and runs fun on a simulator and on device. Any ideas what this error means? Is this just an early Beta 1 bug or might there be anything I can do in my project to fix this? The WWDC24 demo projects all work fine and their previews are working as well. Thanks!
4
0
205
2w
SwiftUI Preview - Undefined symbols for architecture arm64
Starting on Xcode 15.3 and 15.4 my SwiftUI Previews stopped working with the following error: == PREVIEW UPDATE ERROR:     LinkDylibError: Failed to build ContentView.swift          Linking failed: linker command failed with exit code 1 (use -v to see invocation)          ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found     Undefined symbols for architecture arm64:       "static MyLibrary.DisplayUtil.getText() -> Swift.String", referenced from:           closure #1 () -> SwiftUI.Text in (extension in Demo_Broken_Preview_PreviewReplacement_ContentView_1):Demo_Broken_Preview.ContentView.(__preview__body in _1BA320C8FB5388C953E1E463345C3D72).getter : some in ContentView.1.preview-thunk.o       "type metadata accessor for MyLibrary.DisplayUtil", referenced from:           closure #1 () -> SwiftUI.Text in (extension in Demo_Broken_Preview_PreviewReplacement_ContentView_1):Demo_Broken_Preview.ContentView.(__preview__body in _1BA320C8FB5388C953E1E463345C3D72).getter : some in ContentView.1.preview-thunk.o     ld: symbol(s) not found for architecture arm64     clang: error: linker command failed with exit code 1 (use -v to see invocation) After much trial and error, I narrowed it down to my SwiftUI views using properties or functions inside components in Swift Packages. This is a simple example of my Swift Package: public class DisplayUtil {     public func getText() -> String {         return "Text"     }          public static func getText() -> String {         return "Text"     } } And my SwiftUI View import SwiftUI import MyLibrary struct ContentView: View {     var body: some View {         VStack {             Text(DisplayUtil.getText())         }         .padding()     } } #Preview {     ContentView() } The same code works fine on Xcode 15.2 Link to the sample project: https://www.icloud.com/iclouddrive/0c00AD0esi2PwqqiRggokfwGw#Demo%5FBroken%5FPreview Is anybody else having a similar issue?
1
0
432
May ’24
Preview crashed because of a Fatal Error in ModelData.
Can anyone give me assistance on how to fix this. My preview crashed because a Fatal Error in ModelData. This is how my ModelData looks: import SwiftUI struct SutraokeDetail: View { @Environment(ModelData.self) var modelData var sutra: Sutras var body: some View { @Bindable var modelData = modelData ScrollView { CircleImage(image: sutra.image) .offset(y: -130) .padding(.bottom, -130) VStack(alignment: .leading) { HStack{ Text(sutra.name) .font(.title) Spacer() Text(sutra.text) } } } } } #Preview { let modelData = ModelData() return SutraokeDetail(sutra: modelData.sutras[0]) .environment(modelData) }
3
0
299
May ’24
Xcode Previews Fail to Build for all Views in Project
Hello. I've been looking all over this forum and stack and done some internet searches but unfortunately have found nothing to assist in fixing an error I'm receiving on my project in Xcode. Every view shows an error identical to the one shown above, only with that specific file name displayed instead. When I go to fix the error, this is the error detail displayed: == PREVIEW UPDATE ERROR: LinkDylibError: Failed to build TabBar.swift Linking failed: linker command failed with exit code 1 (use -v to see invocation) ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found ld: unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '/Users/brycemchose/Library/Developer/Xcode/DerivedData/Service_Square_App-dnblqgabcrxprhaizjtkcvouyzln/Build/Intermediates.noindex/Previews/iphonesimulator/Service Square App/Products/Debug-iphonesimulator/Service Square.app/Service Square' clang: error: linker command failed with exit code 1 (use -v to see invocation) Note that I can run the app successfully to a simulator or to my iPhone, but cannot see the preview within the Xcode canvas. I've been blindly developing the last two app updates, pushing the changes to the simulator and then tweaking the code based on the simulated version. I can keep doing this for a little while but it is significantly slower and more difficult, especially to fix small bugs and make tiny changes, so I'd really like to see if anyone has an idea for how I can get the preview back to being properly displayed. I'm brand new to this whole thing and have no idea how to fix this issue, so I'd be really grateful if someone with more experience could offer some suggestions! Thanks in advance! :)
2
0
352
May ’24
SwiftUI previews fail with a very simple SwiftPM package
I already filed feedback FB13777941 for this, but wanted to ask if anyone has the same problem, since I can't find anything on google or SO. I created a new package in Xcode (15.3) and added this to it: import SwiftUI struct Test: View { var body: some View { Text("Hello world") } } #Preview { Test() } The package builds, tests can run. Previews don't work. This is more or less the error I get from the diagnostics button (formatted for readability): LoadingError: failed to load library at path ”PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct”: Optional(dlopen(PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct, 0x0000): tried: 'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (no such file), 'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')), '/System/Volumes/Preboot/Cryptexes/OSPATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (no such file), 'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')), 'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/Versions/A/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (no such file), 'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/Versions/A/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')), '/System/Volumes/Preboot/Cryptexes/OSPATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/Versions/A/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (no such file), 'PATH_TO_DERIVED_DATA/Build/Intermediates.noindex/Previews/macos/PACKAGE_NAME/Products/Debug/PackageFrameworks/PACKAGE_NAME_63097C4A372B9C87_PackageProduct.framework/Versions/A/PACKAGE_NAME_63097C4A372B9C87_PackageProduct' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e'))) I don't remember ever having this problem. The arm64 vs arm64e makes no sense to me - why would Xcode get that wrong... and only for previews? I've tried restarting, deleting derived data, the usual rain dances. Any ideas?
5
0
436
May ’24
Conditional compilation with a non-default build configuration
I'm seeing some weird behavior with conditional compilation when I use a build configuration other than "Debug" or "Release", and I'm wondering if I'm doing something wrong or if this is an Xcode bug. The setup Xcode version: 15.3 I have a simple SwiftUI view that takes in a model and displays an attribute of the model. struct ContentView: View { let model: Model var body: some View { VStack { Text("Name: \(model.name)") } .padding() } } In the model file, I have the struct definition, but also an extension that defines some sample data for use in SwiftUI previews: struct Model { let id: String let name: String } #if DEBUG extension Model { static let example = Model( id: "50fef362-f53d-4ded-9168-b887ff62e59d", name: "John Doe" ) } #endif And finally, I have a preview provider that uses this sample data: #Preview { ContentView(model: Model.example) } Normal behavior With the default "Debug" build configuration, this works just fine. There are no compilation errors, and the preview renders as expected. The issue Start off by changing the name of the build configuration to, e.g. "DebugDev" Now I start seeing seeing a mis-match between what happens and what Xcode tells me is happening. The code still compiles and runs, and the SwiftUI preview still works, but Xcode is displaying things as if it doesn't compile. Xcode formats the conditionally compiled code with a lower opacity color as if DEBUG isn't defined: In the view file, I now see a compilation error when referencing the conditionally-compiled code: Autocomplete doesn't work when trying to reference the conditionally compiled code Additional details/observations I have confirmed that the DEBUG active compilation condition is still defined in the build settings. All I've done is change the name of the build config I was initially thinking this might have something to do with the fact that this appears in a preview provider, since those are treated a bit differently, but the same thing happens if I reference the conditionally compiled code directly in the view class Another theory: since I was referencing conditionally compiled code from code that wasn't conditionally compiled, maybe Xcode was trying to tell me that wasn't valid. So, I tried placing the code that calls the conditionally compiled code (in this case, the view class) inside an #if DEBUG. This does get rid of the displayed compilation error, but auto-complete still doesn't work, and the whole class is displayed with the lower-opacity font. Help? I feel like I must be missing something. The only alternative I can think of is that Xcode has some logic hard-coded with the default "Debug" build config, and that would be...just silly.
0
0
271
May ’24
Xcode Preview Broken
On May 1 I started to see this image instead of watch UI preview. It worked well before. I didn't update Xcode, neither I deleted or installed any new simulator OS. It was harmful to my work, since simulator download is 4GB and I need to wait when it downloads, instead of reviewing PRs and closing tasks. Did anyone had the same issue? Do you know how to prevent it?
2
0
293
May ’24