SwiftUI List performance

39,828 results found

Post not yet marked as solved
1 Replies
23 Views
No matter what I have tried, I can't get my test What would you like to do? to appear at the top of the screen. What have I missed? Is something g to do with the ZStack? import SwiftUI import SwiftData struct ContentView: View { @Environment(.modelContext) private var context @Query private var readings: [Readings] @State private var readingTimeStamp: Date = Date() var body: some View { ZStack { Image(IPhone baqckgound 3) .resizable() .aspectRatio(contentMode: .fill) .padding(.top, 40) VStack { Text(What would you like to do?) .font(.title) .fontWeight(.bold) } .padding() Spacer() } } }
Posted
by jamesm46.
Last updated
.
Post not yet marked as solved
1 Replies
It looks like your Spacer() should be inside the VStack, after the Text. You're currently telling SwiftUI to display a background image, then on top of that (because of the ZStack), display Text inside a VStack, but your Text is the only thing in the VStack so it just sits there in the centre. Then you're saying have a Spacer(), but this is inside the ZStack so it isn't pushing the Text up, it's just layered on top of the VStack. The way to fix it is to put the Spacer() in the VStack. You can see this clearly if you change your Spacer() to something like: Rectangle() .fill(Color.green) .frame(width: 100, height: 50) Let's see what it does in the different formats: ZStack { VStack { Text(What would you like to do?) .font(.title) .fontWeight(.bold) } .padding() // -- Outside of the VStack, as you currently have it: Rectangle() .fill(Color.green) .frame(width: 100, height: 50) // Spacer() } So, here, your Spacer() (the Rectangle()) is where your current Spacer() is, and it produces this: Now, moving the
Post marked as solved
1 Replies
23 Views
Map(initialPosition: .camera(mapCamera)) { Marker(Here, coordinate: location) } .frame(height: 300) .clipShape(RoundedRectangle(cornerSize: CGSize(width: 10, height: 10))) .onMapCameraChange(frequency: .continuous) { cameraContext in locationManager.location = cameraContext.camera.centerCoordinate } .onReceive(locationManager.$location, perform: { location in if let location { mapCamera.centerCoordinate = location } }) class LocationDataManager: NSObject, CLLocationManagerDelegate, ObservableObject { enum LoadingState { case loading case notLoading case finished } static let shared = LocationDataManager() private let locationManager = CLLocationManager() @Published var location: CLLocationCoordinate2D? = nil @Published var loading: LoadingState = .notLoading override init() { super.init() locationManager.delegate = self } func resetLocation() { loading = .notLoading location = nil } func getLocation() { locationManager.requestLocation() loading = .loading } func locationManager(_ manager: CLLocationM
Posted
by Xavier-k.
Last updated
.
Post marked as solved
1 Replies
I figured it out. You have to use mapCameraKeyframeAnimator(). @State private var centerCoordinate = CLLocationCoordinate2D(latitude: 38.9072, longitude: -77.0369) @State private var distance: CLLocationDistance = 1000000 @State private var triggerCamera = false Map(initialPosition: .camera(MapCamera(centerCoordinate: centerCoordinate, distance: distance))) { } .frame(height: geo.size.height * 0.60) .shadow(color: .black.opacity(0.5), radius: 1, y: 1) .onReceive(locationManager.$location, perform: { location in if let location { centerCoordinate = location triggerCamera = true } }) .mapCameraKeyframeAnimator(trigger: triggerCamera, keyframes: { camera in KeyframeTrack(MapCamera.centerCoordinate, content: { LinearKeyframe(centerCoordinate, duration: 1) }) KeyframeTrack(MapCamera.distance, content: { LinearKeyframe(300, duration: 1) }) }) Updating the trigger to true will start the animation, which moves to the provided location.
Post not yet marked as solved
2 Replies
20 Views
I am trying to load and view several locations onto a map from a JSOPN file in my SwiftUI project, but I continually encounter the error no exact matches in call to initializer in my ContentView.swift file. What I Am Trying to Do: I am working on a SwiftUI project where I need to display several locations on a map. These locations are stored in a JSON file, which I have successfully loaded into Swift. My goal is to display these locations as annotations on a Map view. JSON File Contents: coordinates: latitude and longitude name: name of the location uuid: unique identifier for each location Code and Screenshots: Here are the relevant parts of my code and the error I keep encountering: import SwiftUI import MapKit struct ContentView: View { @State private var mapPosition = MapCameraPosition.region( MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194), span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05) ) ) @State private var featur
Posted
by deatour.
Last updated
.
Post not yet marked as solved
5 Replies
1.1k Views
Problem The following code doesn't work: let predicate = #Predicate { car in car.size == size //This doesn't work } Console Error Query encountered an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.unsupportedPredicate) Root cause Size is an enum, #Predicate works with other type such as String however doesn't work with enum Enum value is saved however is not filtered by #Predicate Environment Xcode: 15.0 (15A240d) - App Store macOS: 14.0 (23A339) - Release Candidate Steps to reproduce Run the app on iOS 17 or macOS Sonoma Press the Add button Notice that the list remains empty Expected behaviour List should show the newly created small car Actual behaviour List remains empty inspite of successfully creating the small car. Feedback FB13194334 Code Size enum Size: String, Codable { case small case medium case large } Car import SwiftData @Model class Car { let id: UUID let name: String let size: Size init( id: UUID, name: String, size: Size ) { self.id = id s
Posted
by newwbee.
Last updated
.
Post not yet marked as solved
1 Replies
I have a fully Swift & SwiftUI-based app with the following targets: Main app = com.abc.appname Watch app = com.abc.appname.watchkitapp So I'm not sure why your Apps are not connected unless I changed it to com.x.watchkitapp -> com.x.watch. Are you sure you've only tried to change the one bundle id? Have a look through all your targets' Build Settings and make sure everything is in order there. Xcode's settings and how to get everything to link together is sometimes akin to magic. I had massive issues with IntentsExtensions until Apple moved to AppIntents.
Post not yet marked as solved
1 Replies
Actually, I want to add another one: (5) Runtime modifiable ReferenceImageLibrary for Image tracking Also, I want to mention that the reason I listed these features is because all of them are existing features on other systems like iOS and iPadOS, furthermore, some of those are purely software features, so very confused why they are not on Vision Pro/VisionOS
Post not yet marked as solved
1 Replies
103 Views
Dear developers, now that we have played with Vision Pro for 3 months, I am wondering why some features are missing on Vision Pro, especially some seem to be very basic/fundamental. So I would like to see if you know more about the reasons or correct me if I'm wrong! You are also welcome to share features that you think is fundamental, but missing on Vision Pro. My list goes below: (1) GPS/Compass: cost? heat? battery? (2) Moving image tracking: surrounding environment processing is already too computing intensive? (3) 3D object tracking: looks like only supported on iOS and iPadOS, but not visionOS (4) Does not invoke application focus/pause callback: maybe I'm wrong? But we were not able to detect if an app has been put on background or brought to foreground to invoke a callback
Posted
by jjjjjom.
Last updated
.
Post not yet marked as solved
4 Replies
94 Views
I've read the definitive Recording Private Data in the System Log by @eskimo and the words at man 5 os_log and written code to, specifically, turn on Enable-Private-Data in my app. My application is a command line and I've configured Xcode to insert what I believe to be the appropriate incantations in an Info.plist file into the unstructured executable binary. When I run the app with Terminal, I see output in the Console app where I expect values to be displayed in a public manner. Nothing I've read says that Enable-Private-Data doesn't apply to command line apps, and my own understanding of the value of of the logging mechanism rejects that notion because logging is performed all over macOS, not just in a ***.app environment. A this point, I'm firmly convinced this unexpected behavior is of my own doing, but I have paused the search for my (probably embarrassing) mistake, to write this note because of a 1% doubt I'm wrong. I'd be very happy to receive the, expected, assurance that logging configura
Posted Last updated
.
Post not yet marked as solved
1 Replies
65 Views
Why does this Regex Builder code in my SwiftUI app not work? I'm parsing a string that might be a date and time with either AM or PM specified for the time. This bit of code looks for the optional AM or PM. The error I get is: The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions What would 'distinct sub-expressions' mean in this case? The code: let ampmRef = Reference() let ampmReg = Regex { Capture(as: ampmRef) { ZeroOrMore { ChoiceOf { One(am) One(pm) } } } transform: { $0.lowercase } }.ignoresCase() In a related question, is there a way to return a default if the ChoiceOf fails both AM and PM?
Posted
by RJStover.
Last updated
.
Post not yet marked as solved
14 Replies
7.9k Views
We submitted a build to testflight and received a confirmation email it was successfully uploaded. When we open testflight on our iPhone's (X, 6s) we get a message of Could not install appname The requested app is not available or does not exist Where appname is the name of the app. Its very confusing because I can see the build listed in testflight on my mobile device and can view it in iTunes connect. I also can't install prior builds that had worked successfully when I try.
Posted
by SocalAdam.
Last updated
.
Post not yet marked as solved
3 Replies
635 Views
I have an app which uses SwiftUI and Mac Catalyst. When running on a Mac I want to provide a preferences menu entry with the usual keyboard shortcut Command + ,. An implementation via the Settings bundle is out of question since my preferences are too complex for this. Here is a reduced example of my implementation: import SwiftUI @main struct PreferencesMenuTestApp: App { @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate var body: some Scene { WindowGroup { ContentView() } } } class AppDelegate: UIResponder, UIApplicationDelegate { override func buildMenu(with builder: UIMenuBuilder) { let preferencesCommand = UIKeyCommand(title: Preferences…, action: #selector(showPreferences), input: ,, modifierFlags: .command) // let preferencesCommand = UIAction(title: Preferences…) { action in // debugPrint(show preferences) // } let menu = UIMenu(title: Preferences…, options: .displayInline, children: [preferencesCommand]) builder.insertSibling(menu, afterMenu: .about) } @objc func sh
Posted
by RayWo.
Last updated
.
Post not yet marked as solved
3 Replies
Previously, for invalid batch updates UIKit was silently falling back to reload data previously in some cases, resulting in broken animations in certain cases. This is now a hard exception. The exception message should have more information on how to solve this problem; essentially your data source counts before and after the update must line up with the updates you submit. Remember, reloads are decomposed into a delete an an insert. A simple example here: Consider a data source with the following section counts: [10, 20, 30] If you submit an update with INSERT(0,0) // section 0, item 0 RELOAD(1,1) // section 1, item 1 INSERT(1, 2) // section 1, item 2 DELETE(2,1) // section 2, item 1 Then your data source counts must move to the updated values inside the performBatchUpdates: block. In the case of the above updates, that means, for the above update, your data source's implementation of numberOfItemsInSection needs to return 11 for section 0, since one item was inserted 21 for section 1, since one item was ins
Post not yet marked as solved
3 Replies
648 Views
I recently encountered a difficult-to-diagnose bug in an app that I'm working on, and I thought I would share it with the Apple Developer community. The app that I'm working on is an iOS app that uses Core Location's Visit Monitoring API, and it is essential that the app is able to process incoming visits while running in the background. However, after real-world testing, I discovered several crash reports which were difficult to understand, as SwiftUI symbols are not symbolicated on debug builds. Eventually I discovered that the app was crashing when calling an @EnvironmentObject property of the root ContentView from that view's body when the app was launched directly into the background from not running at all. After creating a small test app to isolate the problem, I discovered that any environment object declared in the App struct and referenced from the root ContentView causes the crash, with the exception message: Fatal error: No ObservableObject of type ArbitraryEnvObject found. A View.environ
Posted Last updated
.