Using CloudKit, when I perform CKFetchDatabaseChangesOperation(previousServerChangeToken:) the response in fetchDatabaseChangesCompletionBlock is an error:
Metasync Continuation could not properly be parsed
The first time through this works when the token is nil. The second time through it fails with this error. It was working at one time.
I've tried deleting the app and resetting the development database as well.
I am guessing this has to do with the server change token. I save and restore the server change token to UserDefaults using NSKeyedArchiver to archive/unachive it as Data, so it should be perfectly preserved. I'm using the privateCloudDatabase with a non-default zone.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Why does a swipe action (using the new .swipeAction in SwiftUI 5.5, currently beta 3) set editMode? Notice when you swipe that "Edit" changes to "Done"?
And yet this is not like full edit mode because tapping the EditButton shows the move handles (and the ever-annoying ugly blank indentation for the absent onDelete modifier).
I think my next project won't use SwiftUI.
import SwiftUI
struct Fruit: Identifiable {
let id: UUID = UUID()
let name: String
let color: Color
}
struct ListingView: View {
@State var fruits: [Fruit] = [
Fruit(name: "banana", color: .yellow),
Fruit(name: "apple", color: .green),
Fruit(name: "tomato", color: .red)]
@Environment(\.editMode) private var editMode
var body: some View {
NavigationView {
VStack(alignment: .leading) {
List {
ForEach(fruits) { fruit in
NavigationLink(
destination: ZStack {
fruit.color
Text(fruit.name).bold().font(.largeTitle)
}
.navigationTitle(fruit.name),
label: {
HStack(alignment: .center) {
fruit.color.frame(width: 30, height: 30)
Text(fruit.name)
}
})
.swipeActions(edge: .leading, allowsFullSwipe: false) {
Button(action: { delete(fruit) },
label: { Image(systemName: "trash") }).tint(.red)
}
}
.onMove(perform: { from, to in
fruits.move(fromOffsets: from, toOffset: to)
})
}
}
.navigationBarTitle("Fruits")
.toolbar {
ToolbarItem(placement: .primaryAction) {
EditButton()
}
}
}
}
private func delete(_ fruit: Fruit) {
guard let index = fruits.firstIndex(where: {$0.id == fruit.id}) else { return }
fruits.remove(at: index)
}
}
struct ListingView_Previews: PreviewProvider {
static var previews: some View {
ListingView()
}
}
To implement row reordering I know I could use List{ForEach{}.onMove} but in my situation I can't use List for reasons. So I need to implement my own item reordering using onDrag and onInsert.
These modifiers use NSItemProvider. I think therefore my dragged data type needs to implement NSItemProviderWriting (and NSItemProviderReading). I've looked for examples but the closest code I've found is dragging URLs. When I try to implement these protocols in my type I end up with an error in .onInsert at (NSItemProvider item).loadObject(ofClass:MyType.self) that says "Instance method 'loadObject(ofClass:completionHandler:)' requires that 'MyType' conform to '_ObjectiveCBridgeable'"
How should I be using .onDrag and .onInsert with a custom type?
I've been building my app on Xcode 13 when suddenly it doesn't know about the iOS 15 APIs. Here are a couple error examples:
self.modified = Date.now
// Type 'Date' has no member 'now'
and
operation.modifySubscriptionsResultBlock = { result in
// Value of type 'CKModifySubscriptionsOperation' has no member 'modifySubscriptionsResultBlock'
I can take the exact same code and build it on my other Mac and it builds properly. Both Macs are using Xcode Version 13.0 (13A233) and running macOS 11.6 (20G165). I checked the deployment info for project and target (iOS 15.0), but of course using git I know I have the exact same code base on both machines.
Is there an Xcode preference or system file that got hosed? I tried reinstalling Xcode, but it didn't help.
I want to present a table using SwiftUI. I've gotten most of the way using LazyVGrid.
Problem 1 is the last row's frame paints below the LazyVGrid frame when the last cell is taller than the others.
Problem 2 is the last column shows multiline text. All cells on that row should be aligned using VerticalAlignment.firstTextbaseline. What happens is all of the cells end up vertically aligned.
private var columns: [GridItem] = [
GridItem(.fixed(25)),
GridItem(.fixed(25)),
GridItem(.fixed(30), alignment: .trailing),
GridItem(.flexible())
]
var body: some View {
LazyVGrid(columns: columns, alignment: .leading) {
ForEach(rows) { row in
Text(row.a)
Text("#\(row.b)")
Text("(\(row.c))")
Text(row.d)
.multilineTextAlignment(.leading)
.lineLimit(nil)
}
}
}
I explored using custom alignment guides istead of LazyVGrid, but I don't know how to apply more than one guide to achieve the effect of tab stops for each column.
I am writing a document-based app for macOS using SwiftUI. I want the File menu's New Document command to show a template picker/wizard, and then let the wizard create the document.
How do I structure this? Is there documentation? Examples?
I tried this pattern
@main struct DocDemoApp: App {
var body: some Scene {
WindowGroup { NewDocWizard() }
DocumentGroup(newDocument: { DocDemoDocument() }) {
ContentView(document: $0.document)
}
}
}
The NewDocWizard calls newDocument({ DocDemoDocument() }). But the WindowGroup makes a File > New Window command while DocumentGroup makes the File > New Document command. I need just New Document and it should show the NewDocWizard.
How do I make iCloud optional when using SwiftData? Not all users will have an iCloud account, or allow my app to use iCloud. I want it to gracefully, silently use a local store instead of iCloud if iCloud isn't available. It should also silently handle when the user switches iCloud on or off.
I haven’t done any work for Intents so I don’t know why iOS is making Siri suggestions for my app.
Every now and then, maybe especially in the morning, my iPhone will show a button at the bottom of the Lock Screen with my app icon, the title of a data record from inside my app, and the caption “Siri suggestion”. Tapping it launches my app but that’s it. The app doesn’t show the record.
Why is iOS doing this? Is this some half-baked effect of using iCloud data or Swift Data?
I can’t release the app with iOS doing this, and adding proper Intent support would delay the release.
How can I tell List to animate row height changes?
I have a list whose rows may grow or shrink with user actions. When that happens the List is redrawn with the new heights instantly but the contents slide to their new position. It'd be better if the row heights were animated. Since I don't know what a row's height is I can't use the usual .frame(height: self.animate ? 60 : 90)
This code demonstrates the problem.
struct ContentView: View {
@State private var numbers: [Int] = [0,1,2,3]
var body: some View {
VStack {
List {
Item(numbers: $numbers)
Item(numbers: .constant([9,8,7]))
}
.font(.largeTitle)
HStack {
Button { withAnimation { addNumber() }}
label: { Text("Add") }
Spacer()
Button { withAnimation { removeNumber() }}
label: { Text("Remove") }
}
}
.padding()
}
private func addNumber() {
numbers.append(numbers.count)
}
private func removeNumber() {
numbers = numbers.dropLast()
}
}
struct Item: View {
@Binding var numbers: [Int]
var body: some View {
VStack {
ForEach(numbers, id:\.self) { n in
Text("\(n)")
}
}
}
}
I'm trying to write a unit test for a SwiftData migration. In the teardown function I delete the SQLite container files, but then the underlying sqlite library complains.
There must be a way to gracefully terminate the SwiftData container before I delete the files, but I don't see how. Simplying nil-ifying the references doesn't work. I don't see any obvious close functions, so I hope someone knows a non-obvious function.
override func tearDownWithError() throws {
// Cleanup resources
// -- DOES NOT CLOSE UNDERLYING SQLITE ACCESS --
self.container = nil
self.context = nil
// Delete database
do {
try FileManager.default.removeItem(at: self.url)
}
catch {
// Ignore file not found, report everything else.
let nserror = error as NSError
if nserror.domain != "NSCocoaErrorDomain" && nserror.code == 4 {
throw error
}
}
try? FileManager.default.removeItem(at: self.url.deletingPathExtension().appendingPathExtension("store-shm"))
try? FileManager.default.removeItem(at: self.url.deletingPathExtension().appendingPathExtension("store-wal"))
}
I get these errors for .store, store-shm, and .store-wal:
BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation: vnode unlinked while in use: /Users/(ME)/Library/Developer/XCTestDevices/C52F4E12-EB4F-4639-9866-C3A7126155FA/data/Containers/Data/Application/B0EE90C6-B95D-4185-890D-6F20766B9B3B/tmp/test1.store
invalidated open fd: 11 (0x11)
If the worst comes to the worst, I'll work around it by using a differently-named container for each test, but as they're in tmp they'll get cleaned up for me eventually.
I have a two-view app where the main view is a procedural animation and a secondary view controls settings for the animation. I want to use Play/Pause to toggle between the views, but can't figure out how to do this.
Ideally the main view does not have any visible control and the whole screen can be dedicated to the animation view. Attaching onPlayPauseCommand to the main view does not work. I've also tried managing focus using onFocus without success.
I'm open to other ways to toggle between the main and settings views, it's just that Play/Pause seems the most intuitive.
I'm curious if anyone has a way to remove or move the fixed buttons on the Xcode 12 Touch Bar?
It's 2021 and 3 years ago this was the answer to a similar question. It doesn't discuss the fixed buttons for Run/Stop/Back/Next: https://developer.apple.com/forums/thread/80896?login=true
I am forever hitting the Run button by accident and want to remove it or at least shove it over so no buttons are just right of the escape key on my MBP 2019.
My app deal with a lot of domain-specific jargon. Is there a way to augment the vocabulary used in a SwiftUI TextField (or a UITextInput) so that autocorrection and spelling anticipation will suggest the jargon words first?
Augmentation of dictation support isn't necessary but would be a nice to have.
I've made an "action extension" and now I need to make a glyph or template for NSExtensionServiceFinderPreviewIconName. The documentation has been useless for me.
Everything I do ends up with a generic black image overlaid with some faint template lines:
I understand a glyph ≠ template ≠ icon, but that glyph and template are both acceptable for the action extension. I've tried various ways to make my monochrome, black-and-transparent image but I'm missing something. I started with making it in Sketch. The PNG export has alpha and is black and white, though the color mode of the file is probably full color. I ran it through Icon Set Studio but Xcode warned me there were problems with it, and it came out entirely black.
I took that PNG into Pixelmator Pro and used it to make a clipping mask since one of the hallmarks of a glyph is also supposed to be an alpha mask. Re-exported this new PNG with no change or improvement. Exported it as an SVG, but still nothing helping.
The docs don't say where the image needs to be in the Xcode workspace. I've tried putting it in both the containing app's Asseets.xcassets and in the extension's Media.xcassets, but neither helps.
Once I downloaded a glyph template file (for Sketch) from Apple, but it is tremendously complicated and I hope I can get away without making a version for every font weight and size class.
A step by step guide would help a lot, so if anyone has some energy to make one I bet other indies would appreciate it. We can't all afford $$$ for a graphic artist.
Is there a variant of TextEditor that works with AttributedString? Does it expose the selectedText range?
I want to create a custom text editor to mark ranges of an AttributedString. But I can make do in a clunky way with just String if I at least can get the selectedRange of the text in TextEditor.
I expect I'll need to go to UIKit and use UITextView.