Post

Replies

Boosts

Views

Created

List: Why does the destination value seem to be 0-based in one direction and 1-based in another with .onMove?
I ran into this with a more complex project, but was able to recreate with a very simple example below. I have a List with five items in it. I use a ForEach on the items with .onMove. The onMove function has a destination value. If my list is: A, B, C, D, E, and I drag B so it is below C, I would expect to get A, C, B, D, E. Further, I would expect that destination would be 2, since I am moving B to the 3rd index, assuming that A is at index 0. Weirdly, destination is always 3. Conversely, if I do the opposite, and drag C so it is above B, and I get A, C, B, D, E, destination is now 1! This makes sense, since it's the second position. So why is it that moving down the list results in what appears to be 1-based indexing, but moving it up the list seems to be 0-based indexing? How am I supposed to reliably get the correct destination value? @State var items = ["A", "B", "C", "D", "E"] var body: some View { NavigationStack { List { ForEach(items, id: \.self) { item in Text(item) } .onMove(perform: moveItem) } .toolbar { ToolbarItem { EditButton() } } } } private func moveItem(from source: IndexSet, to destination: Int) { print("destination is \(destination)") } } Output from above. If I drag B below C: destination is 3 If I drag C above B: destination is 1
0
0
256
Oct ’24
How often do you need to update MPNowPlayingInfo?
I am using an AVQueuePlayer to play a series of audio files. While implementing the now playing functionality for the iOS lock screen, I got a little confused with how to use MPNowPlayingInfo. When you update MPNowPlayingInfo, one of the fields is MPNowPlayingInfoPropertyElapsedPlaybackTime. This leads me to believe you need to call it at least once a second to keep that up-to-date. But if you don't call it that frequently, the Now Playing UI does update correctly as it's playing, so that makes me think you only need to call it once you start playing? It feels very expensive to keep on calling it every time in my periodic time observer, but is that the correct approach? Or do you just call it when you play/pause/skip, etc. ?
1
0
581
Sep ’24
Simulator won't sync with CloudKit since Xcode 14
I have a few apps that use Core Data & CloudKit to sync data to multiple devices. Everything was fine until I updated to Xcode 14. Now, although the apps work on an actual device, in the simulator, I get errors about "Failed to sync user keys" and it won't sync anything. I haven't changed the code at all. It just suddenly won't work in the simulator. Since it does this for all apps, I have to believe it's something changed with the simulator? 2022-09-13 12:47:26.766223-0400 Time Since[8061:88974] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(1134): <NSCloudKitMirroringDelegate: 0x600003b540e0>: Failed to set up CloudKit integration for store: <NSSQLCore: 0x1219071d0> (URL: file:///Users/jon/Library/Developer/CoreSimulator/Devices/1990772E-CDF1-4A58-B454-E09D327B2182/data/Containers/Data/Application/3314EA95-4D86-4053-84B3-F1523A57E204/Library/Application%20Support/TimeSince.sqlite) <CKError 0x600000cc1e60: "Partial Failure" (2/1011); "Failed to modify some record zones"; partial errors: { com.apple.coredata.cloudkit.zone:__defaultOwner__ = <CKError 0x600000cc2160: "Internal Error" (1/5000); "Failed to sync user keys"> }>
10
3
3.1k
Sep ’22
iOS Distribution: Missing Private Key
Trying to submit my app to TestFlight. I am getting stuck with a missing private key error. What's weird is that the private key does exist. I can see it in KeyChain. I've only ever used one Mac for development, so it's not like I need to get it form another machine. I tried revoking the cert, and deleting all the Apple Distribution certs/keys from my Keychain. Then I went through the Distribute App process again. Xcode offered to generate a distribution cert for me. I did that. It appears to have created two of them? One looks normal, but the second one is grayed out and says "Not in keychain". The "missing private key" error says I have one Apple Distribution certificate but its private key is not installed. Contact the creator of this certificate to get a copy of the private key. I've looked at a bunch of discussion posts and StackOverflow posts about this, but nothing seems to apply to my specific issue. At least, I tried all those techniques and nothing seems to work. How do I get around this?
10
0
20k
Feb ’21