I can create a List with an EditButton that supports selecting rows. I can also create a List with an EditButton that supports deleting and moving rows. But I can't seem to create a List that supports selecting, moving, and deleting. Is that possible in SwiftUI?
Post
Replies
Boosts
Views
Activity
I've successfully queried lots of HealthKit data, but I'm having trouble querying "appleStandHour" over some time range such as the last week. I'm sure the issue is that this data is a "category" instead of a "statistic". Can someone show me or give me a link that shows how to do this query?
I've spent about six hours so far trying to write a basic example of supporting Siri intents in a SwiftUI app to no avail. It seems most information on this topic online is out of date. I just want do something simple like activate a button in my app with a voice command. Can someone confirm that this is possible?
So far this looks like the best description of the steps to set it up. https://medium.com/simform-engineering/how-to-integrate-siri-shortcuts-and-design-custom-intents-tutorial-e53285b550cf. But I think some steps are missing and it feels very complex.
I created a pair of fairly simple apps (iOS and watchOS) that send messages to each other. It uses the WatchConnectiivity framework. When I run the two apps in the Simulator, I can send messages from the phone to the watch, but I cannot send messages from the watch to the phone. When I attempt that I get the message "Companion app is not installed".
I've seen suggestions that I need to uncheck the "Supports Running Without iOS App Installation" checkbox, but when I do that, the iOS app no longer runs in the Simulator.
My code is here: https://github.com/mvolkmann/watch-with-ios. I'd love to get some hints about how to work past this.
I have a view that is getting large and I want to factor out a chunk of it. One option is to extract a subview by creating a new struct that inherits from View and defines the body property. Another option is to create a function with a return type of some View. It's a bit less code that way. But I get the impression that creating a new View is preferred. What advantages does that have?
struct DemoView: View {
var body: some View {
Text("Demo")
}
}
vs.
func demoView() -> some View {
Text("Demo")
}
Can anyone confirm whether Apple is actively working to improve the Vim mode in Xcode, perhaps adding support for things like the dot command to repeat the last command sequence or adding support for macros?
I have a custom view that is passed a Binding to a String.
The custom view renders a TextField.
I can't find the right syntax to modify the binding after focus leaves the TextField.
The code is something like this:
struct MyURL: View {
private let title: String
@Binding var url: String
@State private var tempUrl: String
init(_ title: String, url: Binding<String>) {
self.title = title
_url = url
_tempUrl = State(initialValue: url.wrappedValue)
}
var body: some View {
TextField(title, text: $tempUrl, onEditingChanged: editingChanged)
.autocapitalization(.none)
.disableAutocorrection(true)
}
}
private func editingChanged(hasFocus: Bool) {
guard !hasFocus else { return }
if !tempUrl.starts(with: "https://"),
!tempUrl.starts(with: "http://") {
tempUrl = "https://" + tempUrl
}
url.wrappedValue = tempUrl // THIS LINE IS WRONG!
}
}
I can use this code to change the background color of the tab bar:
let appearance = UITabBarAppearance()
appearance.backgroundColor = UIColor(bgColor)
let appearance2 = UITabBar.appearance()
appearance2.scrollEdgeAppearance = appearance
appearance2.standardAppearance = appearance
But it seems this is a one-time thing. If I run this code again later with a different value of bgColor, it does not change. What can I do to modify the tab bar background color after I have set the color once? I need this because I am allowing the user to change it.
Is it possible to use LocalNotificationManager to schedule a local notification to be sent every day at a certain time, but run some code before each notification is sent to determine the text of the notification? I know how to do this and send the same message every time, but I need to determine the message to send dynamically.
Apps that support in-app purchases are rejected in App Review unless they implement the ability to restore previous purchases. There is a WWDC 2022 video on doing exactly that and I am doing what that video suggests, but my app is still rejected. Here's what they say:
"When validating receipts on your server, your server needs to be able to handle a production-signed app getting its receipts from Apple’s test environment. The recommended approach is for your production server to always validate receipts against the production App Store first. If validation fails with the error code "Sandbox receipt used in production," you should validate against the test environment instead."
To which I replied:
"I don’t have a server. Can you explain what “your server” means for an iOS app that has no server-side components?"
But they won't explain themselves. They just say:
"Your question requires technical assistance and would be best addressed by Apple Developer Technical Support who can provide discrete code-level assistance for Apple frameworks, APIs, and tools."
Can someone point me to a code example that shows how to do this?
My failed attempt is here: https://github.com/mvolkmann/SwiftUI-GiftTrack/blob/main/GiftTrack/ViewModels/StoreViewModel.swift
Is it possible to write an iOS app that displays the battery percentage of an associated Apple Watch? It seems like it should be possible because the Battery widget supplied by Apple does that. But I haven't been able to find an API for getting that information.
I downloaded and built this app for capturing images that can be used to generate a USDZ 3D model file. But it doesn't work for me. I can take the photos and see them in the app, but there are not saved. Here are some of the log messages produced by the app. Note the last line.
Creating capture path: "file:///var/mobile/Containers/Data/Application/40A7C69A-DE34-43B8-A1DF-D3BB87D5C23E/Documents/Captures/Jan%2029,%202023%20at%201:33:54%20PM/"
Got back dual camera!
didSet setupResult=success
Starting session...
Capture photo called...
Found available previewPhotoFormat: Optional(["PixelFormatType": 875704422, "Width": 512, "Height": 512])
inProgressCaptures=1
Captured gravity vector: Optional(__C.CMAcceleration(x: 0.033207084983587265, y: -0.7901527881622314, z: -0.6120097041130066))
DidFinishProcessingPhoto: photo=<AVCapturePhoto: 0x280e04290 pts:388734.243725 1/1 settings:uid:4 photo:{4032x3024 SIS:ON} prev:{512x384} thumb:{512x384} time:0.741-0.797>
[CIImage initWithCVImageBuffer:options:] failed because the buffer is nil.
In a Swift Chart that listens for drag gestures in order to display a RuleMark with an annotation, the y-axis scale changes while dragging which causes the entire chart to jump. I have a small code example that demonstrates this at https://github.com/mvolkmann/ChartJump. See the two screenshots there.
I have an app that adds cycling workouts to HealthKit. Here is the snippet of code that does it.
let workout = HKWorkout(
activityType: HKWorkoutActivityType.cycling,
start: startTime,
end: endTime,
duration: 0, // compute from start and end data
totalEnergyBurned: HKQuantity(
unit: .largeCalorie(),
doubleValue: Double(calories)
),
totalDistance: HKQuantity(unit: .mile(), doubleValue: distance),
metadata: nil
)
try await store.save(workout)
This successfully adds a workout and the number of calories is recorded in the Health app. However, the iOS Fitness app and the watchOS Activity app do not recognize the calories so the MOVE ring is not affected. What else do I need to do to let those apps know that my workout burned calories?
I wrote an app that successfully adds a cycling workout to HealthKit. I can see in the Health app that there are new entries under "Workouts", "Active Energy", and "Exercise Minutes" all from me just adding an HKWorkout and a HKQuantitySample.
However, there is no new entry for "Cycling Distance". I assumed that since the workout I added includes the fact that the activityType is HKWorkoutActivityType.cycling and I provided the distance, that it would also add an entry for "Cycling Distance". Is there something extra I need to do to get that?