When developing a CloudKit application, the standard recommendation is to create an iCloud account for testing. That makes a lot of sense as I’d like to keep developing code far from my personal iCloud account. But the CloudKit Dashboard won’t let me view the private database for that account. What do other people do to check their work?* clarification: I mean on the development server, not the production server.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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.
Is there a way to view the contents of an app's NSUbiquitousKeyValueStore? I was expecting to find a property or method that listed the keys, or maybe a web app like the CloudKit Dashboard.
I would like the first() operator to send a value as soon as it's received a value that satisfies the condition (and to finish publishing as well). But I don't know how to test this is really happening. The only test I've devised is below, but I suspect it is wrong. The map operator will keep demanding values of course, so I expect it to print all of them. Yet the sink subscriber doesn't invoke receiveValue or receiveCompletion until after map is done, which suggests first is awaiting upstream completion. Does first really does need the upstream to complete before it sends anything onward? What's really the story here for first?
import Foundation
import Combine
let numbers = (-10...10)
let cancellable = numbers.publisher
.map({ n in
Thread.sleep(forTimeInterval: 1)
print("sending \(n)")
return n
})
.first { $0 0 }
.sink { completion in
switch completion {
case .failure(_): print("failed")
case .finished: print("finished")
}
} receiveValue: { print("\($0)") }
My specific situation is I'm monitoring for when the network becomes available the first time. Of course the monitoring source will never (should never) finish but I do want completion for a pipeline subscribing to that monitor with first.
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.
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()
}
}
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.
Similarly to this old post [https://developer.apple.com/forums/thread/130969] I am getting a "ThreadSanitizer: CHECK failed" before my code seems to have launched. Is this something I should spend time trying to reproduce in a small project or is it an Xcode bug others are getting too?
Turning off the sanitizer is my dirty workaround for now.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Xcode
Beta
Xcode Sanitizers and Runtime Issues
ScrollViewReader doesn't seem to work reliably with an animated alignmentGuide view as the target. If I scroll by hand then SVR will track the animated guide. Rescaling the content often breaks the behavior and requires another manual scroll to reconnect the animation to scrolling.
In my test I have a media player-like timeline. I'd like to keep the elapsed time cursor centered, no matter the length of the timeline rectangle.
struct ContentView: View {
@State private var zoom: Double = 10
let start = Date.now
let duration: TimeInterval = 60
var body: some View {
VStack(alignment: .leading) {
TimelineView(.periodic(from: start, by: 1)) { context in
let elapsed = context.date.timeIntervalSince(start)
ScrollViewReader { proxy in
ScrollView(.horizontal) {
Text("\(elapsed.formatted(.number.precision(.fractionLength(0)))) / \(duration.formatted(.number.precision(.fractionLength(0))))")
let barWidth: CGFloat = max(300, duration * zoom)
ZStack(alignment: Alignment(horizontal: .marker, vertical: .bottom)) {
ZStack(alignment: .leading) {
// The bar representing the duration.
Rectangle().fill(Color.gray)
// The bar representing the elapsed time.
Rectangle().fill(Color.accentColor)
.frame(width: barWidth * (elapsed / duration))
.alignmentGuide(.marker) { d in d[.trailing] }
}
.frame(width: barWidth, height: 20)
Rectangle().fill(Color.primary).frame(width: 3)
.alignmentGuide(.marker) { d in d[HorizontalAlignment.trailing] }
.id(1)
}
.frame(height: 30)
.onChange(of: elapsed, perform: { _ in proxy.scrollTo(1, anchor: .center) })
}
.onChange(of: elapsed, perform: { newValue in if newValue > duration { exit(0) } })
}
}
Slider(value: $zoom, in: 0.5...40, label: { Text("Zoom") })
let s = zoom.formatted(.number.precision(.fractionLength(1)))
Text("\(s)")
}
.padding()
}
}
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.
When I save an item which is a FileRepresentation to the File system/Files app, TWO files are saved: the shared file, and simple text file containing the message text. I don't want the user to get the message in a text file when they save that way. Sure I can just leave out the message parameter, but then it's useful if they want to email the file somewhere? Is there a way to have a message text that isbn't saved in a file?
ShareLink(item: ...,
subject: Text("..."),
message: Text("..."), //⬅ this text gets saved in a 2nd file
preview: SharePreview("...", image: ...)) {
Label { Text("...") } icon: { Image(systemName: "square.and.arrow.up") }
}
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.
Is there a clean way to add an auxilliary view to the SwiftUI .searchable view? The best I have found is to add a VStack above the list being searched, but this makes the removal transition behave funny.
("Funny" means the search view and aux views animate away fine, but after they finish animating the List view snaps to the top of the screen, hiding the idle search field. The normal behavior leaves the idle search field showing.)
NavigationStack {
MyListView().searchable(...)
}
———
struct MyListView: View {
@Environment(\.isSearching) private var isSearching
var body: some View {
if isSearching {
VStack {...my auxilliary view...}
}
List {...}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
I made a subclass of UICollectionViewCell and Swift is complaining that I'm not allowed to use superclass properties like bounds, backgroundView or selectedBackgroundView. This very code was given by Appleʼs documentation - https://developer.apple.com/documentation/uikit/uicollectionviewdelegate/changing_the_appearance_of_selected_and_highlighted_cells so I don't understand why it's disallowed.
I declared class MyCollectionViewCell: UICollectionViewCell method awakeFromNib.
class MyCollectionViewCell: UICollectionViewCell {
...
override class func awakeFromNib() {
...
let redView = UIView(frame: bounds)
redView.backgroundColor = colorLiteral(red: 1, green: 0, blue: 0, alpha: 1)
self.backgroundView = redView
let blueView = UIView(frame: bounds)
blueView.backgroundColor = colorLiteral(red: 0, green: 0, blue: 1, alpha: 1)
self.selectedBackgroundView = blueView
Xcode 12.2 gives an error about bounds, backgroundView, and selectedBackgroundView saying stuff like "Instance member 'bounds' cannot be used on type 'MyCollectionViewCell'".
If I declare a variable as UICollectionViewCell I can set these properties in it, but a function in a subclass of UICollectionViewCell cannot access its own properties?