Post

Replies

Boosts

Views

Activity

Reply to how to update SwiftUI Map via MapCamera approach with data from @Observable? (see code)
Here you go // // ContentView.swift // ForumMapsQuestion // // Created by SB on 2024-01-05. // import SwiftUI import MapKit struct ContentView: View { @StateObject var locationMgr = NewLocationManager() @State private var mapCamPos: MapCameraPosition = .automatic var body: some View { ZStack { Map(position: $mapCamPos) .onReceive(locationMgr.$direction) { direction in mapCamPos = .camera(MapCamera( centerCoordinate: self.locationMgr.location.coordinate, distance: 800, heading: direction )) } .onReceive(locationMgr.$location) { location in mapCamPos = .camera(MapCamera( centerCoordinate: location.coordinate, distance: 800, heading: self.locationMgr.direction )) } VStack (alignment: .leading) { VStack { Text("Location from observable: \(locationMgr.location.description)") Text("Direction from observable: \(locationMgr.direction)") } .padding() .background(.gray) .clipShape(RoundedRectangle(cornerSize: CGSize(width: 20, height: 10))) .opacity(0.7) Spacer() } } } } #Preview { ContentView() } final class NewLocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { @Published var location: CLLocation = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 51.500685, longitude: -0.124570), altitude: .zero, horizontalAccuracy: .zero, verticalAccuracy: .zero, timestamp: Date.now) @Published var direction: CLLocationDirection = .zero private let locationManager = CLLocationManager() override init() { super.init() locationManager.startUpdatingLocation() locationManager.delegate = self Task { [weak self] in try? await self?.requestAuthorization() } } func requestAuthorization() async throws { if locationManager.authorizationStatus == .notDetermined { locationManager.requestWhenInUseAuthorization() } } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { locations.forEach { [weak self] location in Task { @MainActor [weak self] in self?.location = location } } } func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { Task { @MainActor [weak self] in self?.direction = newHeading.trueHeading } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’24
Reply to SwiftUI against SwiftData is too fragile and error prone
Then, you're using the wrong hammer for the nail in question. There are many SwitfUI sample apps available that you can use as a reference for the architecture employed by Apple, such as MVC and MVVM. The language is designed to be semicolonless unless multiple statements are being packed into one line, which then calls for a semicolon. This sounds like your first go at SwiftUI and SwiftData. My recommendation will be to study the SwiftData Sample applications such as BackyardbirdsbuildingAnAppWithSwiftData, to see how Apple approached the issue.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’23
Reply to How to prevent singleton base class getting re-initialised
import SwiftUI @main struct BlueTest1App: App { @State private var manager = BLEManager() var body: some Scene { WindowGroup { ContentView(bleManager: manager) } } } OR import SwiftUI @main struct BlueTest1App: App { @State private var manager = BLEManager() var body: some Scene { WindowGroup { ContentView() .envitonmentObject(manager) } } } struct ContentView: View { @EnvironmentObject private var bleManager: BLEManager ... }
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’23
Reply to Error
Provide any missing images
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to I want to port my metaverse app with WebRTC to visionOS but I encountered some problem.
If it doesn't compile, then it's not supported by the library. Please ask your question on the unity developers forum. Unity is not an Apple product.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to 4+ weeks of waiting for Family Controls Entitlement
Well Apple does go on a Christmas break
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to Xcode debugger doesn't pause on breakpoints (simulator SDK < iOS 17)
Yup I have also noticed the same issue it’s as if the debugger is not connected to the sim.
Replies
Boosts
Views
Activity
Jan ’24
Reply to how to update SwiftUI Map via MapCamera approach with data from @Observable? (see code)
Here you go // // ContentView.swift // ForumMapsQuestion // // Created by SB on 2024-01-05. // import SwiftUI import MapKit struct ContentView: View { @StateObject var locationMgr = NewLocationManager() @State private var mapCamPos: MapCameraPosition = .automatic var body: some View { ZStack { Map(position: $mapCamPos) .onReceive(locationMgr.$direction) { direction in mapCamPos = .camera(MapCamera( centerCoordinate: self.locationMgr.location.coordinate, distance: 800, heading: direction )) } .onReceive(locationMgr.$location) { location in mapCamPos = .camera(MapCamera( centerCoordinate: location.coordinate, distance: 800, heading: self.locationMgr.direction )) } VStack (alignment: .leading) { VStack { Text("Location from observable: \(locationMgr.location.description)") Text("Direction from observable: \(locationMgr.direction)") } .padding() .background(.gray) .clipShape(RoundedRectangle(cornerSize: CGSize(width: 20, height: 10))) .opacity(0.7) Spacer() } } } } #Preview { ContentView() } final class NewLocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { @Published var location: CLLocation = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 51.500685, longitude: -0.124570), altitude: .zero, horizontalAccuracy: .zero, verticalAccuracy: .zero, timestamp: Date.now) @Published var direction: CLLocationDirection = .zero private let locationManager = CLLocationManager() override init() { super.init() locationManager.startUpdatingLocation() locationManager.delegate = self Task { [weak self] in try? await self?.requestAuthorization() } } func requestAuthorization() async throws { if locationManager.authorizationStatus == .notDetermined { locationManager.requestWhenInUseAuthorization() } } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { locations.forEach { [weak self] location in Task { @MainActor [weak self] in self?.location = location } } } func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { Task { @MainActor [weak self] in self?.direction = newHeading.trueHeading } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to IPHONE 13 GLITCH/UNRESPONSIVE
Sorry this forum is dedicated exclusively to developer-related activity and questions. Your questions can be best served by an Apple Store Genius or in the customer retail forums https://discussions.apple.com/welcome
Topic: App & System Services SubTopic: Hardware Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to Can we use voiceOver (speak out) and voice control (voice command) when user turned OFF both voiceOver and voice control in settings > accessibility? .
You don't control it. The user controls it via Accessibility features.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jan ’24
Reply to Xcode and iOS Emulator 17.2 Error
Simulator
Replies
Boosts
Views
Activity
Jan ’24
Reply to SwiftUI against SwiftData is too fragile and error prone
Then, you're using the wrong hammer for the nail in question. There are many SwitfUI sample apps available that you can use as a reference for the architecture employed by Apple, such as MVC and MVVM. The language is designed to be semicolonless unless multiple statements are being packed into one line, which then calls for a semicolon. This sounds like your first go at SwiftUI and SwiftData. My recommendation will be to study the SwiftData Sample applications such as BackyardbirdsbuildingAnAppWithSwiftData, to see how Apple approached the issue.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to Apple doc still refers to nonexistent info.plist. Should we use the entitlements file instead?
Here is the entry when info.plist is autogenerated true.
Topic: Code Signing SubTopic: Entitlements Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to Apple doc still refers to nonexistent info.plist. Should we use the entitlements file instead?
Refer to the info.plist options in build settings when autogenerate info.plist is true.
Topic: Code Signing SubTopic: Entitlements Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to Uploading Unity project to Xcode
Unity-Xcode integration questions will have to be posted on the Unity boards for a Unity representative to provide assistance.
Replies
Boosts
Views
Activity
Dec ’23
Reply to Did iOS 17.2 break zIndex?
If there is no parent ZStack then the .zIndex modifier is ineffective.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to Storage issue with not installed os update
@PatrickPaniew - Your question will be better served in the retail customer support forums here https://discussions.apple.com/welcome. Sorry, but this board is for 3rd party Apple developer related discussions.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Dec ’23
Reply to How to prevent singleton base class getting re-initialised
import SwiftUI @main struct BlueTest1App: App { @State private var manager = BLEManager() var body: some Scene { WindowGroup { ContentView(bleManager: manager) } } } OR import SwiftUI @main struct BlueTest1App: App { @State private var manager = BLEManager() var body: some Scene { WindowGroup { ContentView() .envitonmentObject(manager) } } } struct ContentView: View { @EnvironmentObject private var bleManager: BLEManager ... }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’23