Xcode Previews

RSS for tag

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

Xcode Previews Documentation

Posts under Xcode Previews tag

108 Posts
Sort by:
Post not yet marked as solved
1 Replies
50 Views
It keeps saying "iOS 17.0 Not Installed" and I cannot build and run my app. When I click the "GET" button, a new window popped up and it clearly stated that iOS 17.0 Simulator was installed. I already tried reinstalling Xcode, but the problem is still there. Any suggestion is appreciated!
Posted
by marticztn.
Last updated
.
Post not yet marked as solved
1 Replies
116 Views
Can't compile existing project with new #Preview macros. Get: 'Preview' is only available in application extensions for iOS 17.0 or newer And because macros generate struct I can't use #available to fix this. Does anyone have any ideas how to fix this? I guess the only solution is to create new macros that will work like #available(iOS 17) { code } and remove the code for older iOS?
Posted Last updated
.
Post marked as solved
6 Replies
1.1k Views
HI, I have an issue displaying SwiftUI previews with Xcode 14. My project has iOS and an watchOS Target. It also includes a lot of SPM, most of them only used by the PhoneApp. The project build successfully for both iOS and watchOS. I can see that when building the watch target, only SPM that are included in this target are build for for watchOS The issue is when I try to build a swiftUI preview of the watch target. In this case I can see on the build for Preview log that Xcode try to build ALL spm defined in the Xcode project, including the one that are not used by the watch Target, As a lot if spm are for iOS only, and doesn't build for watchOS, the build for preview fails, and I'm unable to preview my swiftUI views on the AppeWatch. Note that my project is working fine on Xcode 13. This issue is easy to reproduce in any Xcode projects containing a iOS and watchOS target by adding a SPM that is only for iOS. Any workaround to fix this issue ?
Posted Last updated
.
Post not yet marked as solved
5 Replies
2.4k Views
In Xcode 13, I can use groups to preview my views in different states: In Xcode 14 (Beta 1) groups are now rendered as tabs, making it way more difficult to verify all states after changes: Is there a way to toggle back to the old behavior - or is there any other container view that would be more suitable?
Posted
by paxos.
Last updated
.
Post not yet marked as solved
2 Replies
1.2k Views
Failed to decode landmarksData.json from bundle because it appears to be invalid JSON. Full disclosure - Im extremely new to this and am playing around with the swift tutorials to see what it can do and see if I could build an app. Any advice is appreciated. I added a few locations to the SwiftUI Tutorial for Lanmarks and this is what happened. I have checked that JSON file and all commas are in the correct place everything is correct but im getting this error. Not sure what im doing incorrectly. Can anyone give me assistance on how to fix this. I can only preview favorite button, circle image and map. Everything else appears as Fatal Error in ModelData.
Posted
by KErickson.
Last updated
.
Post not yet marked as solved
2 Replies
233 Views
I have an app with some SwiftUI Views. When using preview in Xcode, Xcode creates many instances of the previews. Then I quit Xcode, but the previews are not quit. I have to force quit them in Menu -> Apple Icon Menu -> Force Quit. Has anyone seen the same thing? How to solving it? Xcode 14.3 (14E222b) macOS Ventura 13.3.1 (a) (22E772610a) Mac mini M1 16G 512G
Posted
by zhaoxin.
Last updated
.
Post not yet marked as solved
2 Replies
650 Views
Hi all, I'm trying to preview a very simple view in a project I have in SwiftUI, and I'm getting this error regardless of the view I'm trying to preview: ---------------------------------------- LinkDylibError: Failed to build PreferencesView.swift Linking failed: linker command failed with exit code 1 (use -v to see invocation) ld: warning: directory not found for option '-F/Applications/Xcode-13.3.1.app/Contents/SharedFrameworks-iphonesimulator' Undefined symbols for architecture x86_64: "___asan_init", referenced from: _asan.module_ctor in Pods_Remoti(Pods-Remoti-dummy.o) "___asan_version_mismatch_check_apple_clang_1316", referenced from: _asan.module_ctor in Pods_Remoti(Pods-Remoti-dummy.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ================================== (I'm attaching the whole error in the post, because it's way too long) Am I doing something wrong here? Thanks in advance!
Posted
by noloman.
Last updated
.
Post not yet marked as solved
4 Replies
1.5k Views
Hi everyone, I'm trying to follow the Landmarks project tutorial and got stuck in the second part, in the second section (Create the Row View), step 6 where it says "Modify the text view to use the landmark property’s name." This must be done in the LandmarkRow.swift file. https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation The tutorial shows that after doing this, the preview will display the name of the landmark (Turtle Rock) instead of the usual "Hello world" greeting. But my replacement is not happening. Moreover, from this point on, the preview stops working. There are no error messages in the code, except for the message that the preview could not be performed. I checked and rewrote the code several times, replaced the data source files, but nothing helped. At the same time, the preview works well in other view files. I can't figure out what's wrong with my code? Any ideas as to what the reason will be is appreciated. Below is the code of two files, the LandmarkRow.swift, where view does not work, the second is ModelData.swift and it is related to the previous one. LandmarkRow.swift import SwiftUI struct LandmarkRow: View {     var landmark: Landmark     var body: some View {         HStack {             landmark.image                 .resizable()                 .frame(width: 50, height: 50)             Text(landmark.name)             Spacer()         }     } } struct LandmarkRow_Previews: PreviewProvider {     static var previews: some View {         LandmarkRow(landmark: landmarks[0])     } } ModelData.swift import Foundation var landmarks: [Landmark] = load("landmarkData.json") func loadT: Decodable(_ filename: String) - T {     let data: Data     guard let file = Bundle.main.url(forResource: filename, withExtension: nil)     else {         fatalError("Couldn't find \(filename) in main bundle")     }     do {         data = try Data(contentsOf: file)     } catch {         fatalError("Couldn't load \(filename) from main bundle:\n\(error)")     }     do {         let decoder = JSONDecoder()         return try decoder.decode(T.self, from: data)     } catch {         fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")     } }
Posted
by John368.
Last updated
.
Post not yet marked as solved
24 Replies
11k Views
I keep getting a Xcode Previews error in Xcode 12 from a package that imports other packages. As soon as I remove the dependency I'm able to see the SwiftUI preview. I'm only able to use previews in packages that have no dependencies The error I get is: "LoadingError: failed to load library at path...Library not loaded " then it point to the dependency that it could not load in the current package. How can I access Xcode Previews from a package that depends on other packages?
Posted
by iamlogiq.
Last updated
.
Post marked as solved
4 Replies
949 Views
Hey, I want my preview to only have the size of the view and not show the whole iPhone. I have already tried it with this code: struct TimerCardView: View { var body: some View { Text("Hello, World!") .padding() .background(.gray) } } struct TimerCardView_Previews: PreviewProvider { static var previews: some View { TimerCardView() .previewLayout(.sizeThatFits) } } but nothing happened. What am I doing wrong? I appreciate help
Posted Last updated
.
Post not yet marked as solved
13 Replies
7.0k Views
I am experiencing an issue where my Mac's speakers will crackle and pop when running an app on the Simulator or even when previewing SwiftUI with Live Preview. I am using a 16" MacBook Pro (i9) and I'm running Xcode 12.2 on Big Sur (11.0.1). Killing coreaudiod temporarily fixes the problem however this is not much of a solution. Is anyone else having this problem?
Posted
by joltguy.
Last updated
.
Post not yet marked as solved
1 Replies
176 Views
Even though the code is 100% works in the simulator, the preview canvas gets "Cannot preview in this file" error more often. How could I get the issue sorted? The issue is sorted after restarting the xcode several times. I tried to attache the generated report as a zip file, but it does not support to attach.
Posted
by rasangalk.
Last updated
.
Post not yet marked as solved
1 Replies
171 Views
Hello, I've completed the Landmarks App Apple Developer tutorial, since finishing it I decided to create a project using the .JSON code from the project. I've wrote the code in an identical layout as the tutorial, however I am receiving the error - Couldn't parse lesssonData.json as array - when trying to load a preview and the app builds successfully but crashes when I launch it. Below is the code, any help is appreciated! LessonList.swift import SwiftUI struct LessonList: View { var lesson: Lesson var body: some View { VStack { List { Section { ForEach(lessons, id: \.self) { lesson in Label(lesson.name, systemImage: "house") } } Section { Label("Hello World!", systemImage: "globe") } } } } } struct LessonList_Previews: PreviewProvider { static var lessons = ModelData().lessons static var previews: some View { LessonList(lesson: lessons[0]) } } ModelData.swift import Foundation import Combine final class ModelData: ObservableObject { @Published var lessons: [Lesson] = load("lessonData.json") } var lessons: [Lesson] = load("lessonData.json") func load<T: Decodable>(_ filename: String) -> T { let data: Data guard let file = Bundle.main.url(forResource: filename, withExtension: nil) else { fatalError("Couldn't find \(filename) in main bundle.") } do { data = try Data(contentsOf: file) } catch { fatalError("Couldn't load \(filename) from main bundle:\n\(error)") } do { let decoder = JSONDecoder() return try decoder.decode(T.self, from: data) } catch { fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)") // Error on this Line } } lessonData.JSON [ { "id":"1001", "lessonNo":"Lesson 1", "name":"Introduction to Photography", "category":"Introduction", }, { "id":"1002", "lessonNo":"Lesson 2", "name":"Negative and Positive Space", "category":"Introduction", }, { "id":"1003", "lessonNo":"Lesson 3", "name":"Introduction to Camera Angles", "category":"Introduction", }, { "id":"1004", "lessonNo":"Lesson 4", "name":"Lighting and Framing", "category":"Beginners", }, { "id":"1005", "lessonNo":"Lesson 5", "name":"Still Photography", "category":"Beginners", }, { "id":"1006", "lessonNo":"Lesson 6", "name":"Motion Photograhy", "category":"Beginners", }, { "id":"1007", "lessonNo":"Lesson 7", "name":"Aperture and F-Stops", "category":"Intermiediate", }, { "id":"1008", "lessonNo":"Lesson 8", "name":"Shutter Speeds", "category":"Intermiediate", }, { "id":"1009", "lessonNo":"Lesson 9", "name":"Advanced Framing", "category":"Advanced", }, { "id":"1010", "lessonNo":"Lesson 10", "name":"Advanced Aperture, F-Stops and Shutter Speeds", "category":"Advanced", }, ]
Posted
by E-K.
Last updated
.
Post not yet marked as solved
3 Replies
402 Views
Since updating to Big Sur 11.7.5 I am unable to preview any Views or run the Playground both continue to create Crash Reports until Xcode is stopped. The Preview panel remains blank or the Playground never runs. Crash Report attached below which indicates that the update has moved a Library called AddressBook and Xcode can no longer locate it. NPKCompanionAgent_2023-04-06-140115_Johns-iMac.crash
Posted
by jps22.
Last updated
.
Post not yet marked as solved
4 Replies
712 Views
Hi, when I try to preview any Xcode SwiftUI project on my external device (iPhone 12 iOS 16.1.1) I always get the message: FailedToTransferItemError: Failed to copy "ContentView.1.preview-thunk.dylib" to device ================================== |  HumanReadableNSError: The operation couldn’t be completed. (OSStatus error -10814.) |   |  NSOSStatusErrorDomain (-10814): |  ==NSDebugDescription: Unable to find this application extension record in the Launch Services database. |  ==_LSLine: 685 |  ==_LSFunction: _LSPluginFindWithPlatformInfo |   |  ================================== |   |  |  MessageSendFailure: Message send failure for transferring ContentView.1.preview-thunk.dylib Xcode - Version 14.1 (14B47b) This happens with all Xcode projects, even the simple 'Hello World' template. Preview in the Xcode canvas area works fine, also the simulator.
Posted Last updated
.
Post not yet marked as solved
13 Replies
2.5k Views
Hello, I have been working with storyboards for my projects without any problems. However, since the XCode Version 14.0 (14A309), the "safe area" on the storyboard preview is wrong for landscape orientation, as you can see in the image below: The "safe area" acts as in portrait (with margins on top and bottom) instead of margins on the left and right side as in the previous version. Also changing the device for preview does not help. It seems to affect only the preview, as the safe area is well in place after building it on both iPhone 13 and iPhone 12 mini. Do you have any idea how to fix this? Or is it a bug that should be fixed by the Apple developer team? Thanks
Posted
by WizAxel.
Last updated
.
Post not yet marked as solved
18 Replies
7.2k Views
I'm trying out Xcode 12 (beta) and encountered an issue with TextField when viewing it in a live Preview. Although the view is interactive (scrolling vertically seems to be OK) and a cursor appears in the TextField view when it is clicked on, keyboard input is ignored. The same code works as expected in Xcode 11.5. Simulator in both 11.5 and 12 exhibits expected behaviour. Is this a bug? I know there is an issue with interactivity in Preview with multiple views inside PreviewProvider but I'd assumed this is if you'd added multiple Views to the same body of this struct.
Posted Last updated
.
Post not yet marked as solved
1 Replies
165 Views
I did a fair amount of work and there was an issue with dragging pointing and hitting the edge I couldn't fix. Once I ran it on device I noticed that was fine, but it looks wrong. It looks like an iPhone 8 layout on my iPhone 13 Pro Max. Nothing I do seems to fix this, can anyone help. I am a new developer, and this is my first time posting on these forums so hello as well.
Posted
by ipah.
Last updated
.