Post

Replies

Boosts

Views

Activity

Reply to Ornament Toolbar disappears
I am experiencing a similar issue. I have a UIKit MapViewController() where I declare a UIHostingOrnament. This is one view of a SwiftUI TabView. I have the below code in my viewIsAppearing. #if os(visionOS) mapView = MKMapView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) let ornament = UIHostingOrnament(sceneAnchor: .bottom, contentAlignment: .center) { ToolbarView() .glassBackgroundEffect() } self.ornaments = [ornament] #else Do other stuff here #endif When I select the tab for the Map View the first time, I see the ornament at the bottom, but when I select another tab and then select the Map tab, the ornament has disappeared. I can see that the viewIsAppearing is executing every time I click on the Map tab.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23
Reply to 'UIStoryboard' and 'UIStoryboardSegue' was deprecated in visionOS 1.0 - Why?
When my destination is 'visionOS Designed for iPad', I get no errors and no warnings. But my tabs are now at the bottom and not on the left side. It's okay to use a Storyboard and StoryboardSegue with visionOS if it's run as an iPad app, but not as a standalone app. It doesn't make sense to me at all. Oh yeah, interface builder products are being deprecated as well.
Topic: UI Frameworks SubTopic: UIKit Tags:
Sep ’23
Reply to SwiftData Aggregation
import SwiftData @Model public class Person { var name: String var age: Int init(name: String, age: Int) { self.name = name self.age = age } } You'll probably want to do the below differently. The below ViewController is just given to you for ideas. import UIKit import SwiftData class ViewController: UIViewController { var container: ModelContainer? var context: ModelContext? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. do { let schema = Schema([Person.self]) let modelConfig = ModelConfiguration(schema: schema, cloudKitDatabase: .private("iCloud.com.yourcompany.ClassStats")) container = try ModelContainer(for: schema, configurations: [modelConfig]) if let container = container { context = ModelContext(container) context?.autosaveEnabled = true } } catch { print(error) } } func getStats() { let minAge = 20 let maxAge = 40 let predicate = #Predicate<Person> { person in person.age >= minAge && person.age <= maxAge } let sortBy = [SortDescriptor<Person>(\.name)] var descriptor = FetchDescriptor<Person>(predicate: predicate, sortBy: sortBy) if let persons = try? context?.fetch(descriptor), persons.count > 0 { let count = persons.count } } }
Aug ’23