Post

Replies

Boosts

Views

Activity

Xcode 13 suddenly using old frameworks
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.
1
0
1k
Sep ’21
Custom File "New Document" to show template-picker in a document-based app
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.
1
0
1.6k
Jan ’23
tvOS play/pause gesture and non-av views
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.
1
0
825
Apr ’24
Using KeyFrameTimeline as value for .keyFrameAnimator view modifier
I have several views I want to animate in concert. I plan to use keyframe animation. I want to keep the .keyFrameAnimator modifier code small; I have a lot of ...Keyframes inside several KeyframeTracks. It seems like I should be able to isolate the body of the keyframes parameter into a func or var. Builders are such a pain, I can't grok the right way to refactor their bodies out. I've tried to make a standalone @KeyframeTrackContentBuilder<MyValue> function but cannot figure out the right syntax/incantation to stuff it with KeyframeTracks. My latest attempt is to create a func that returns a KeyframeTimeline, but that's been a deadend too. let k: KeyframeTimeline<MyValue> = timeline(...) CartoonCardView(color: .yellow) .keyframeAnimator( initialValue: k.value(time: 0) ) { content, value in content .rotationEffect(value.angle) .scaleEffect(value.scale) .offset(value.offset) } keyframes: { _ in k } The error on k in the last line is "No exact matches in call to static method 'buildExpression'" with the sub-error "Candidate requires that 'KeyframeTimeline' conform to 'KeyframeTrackContent' (requirement specified as 'K' : 'KeyframeTrackContent') (SwiftUICore.KeyframesBuilder)"
4
0
977
Jul ’24
Single window keyboard shortcut
I made a macOS document-based app that has a second scene that's a Window. It's name appears in the single window list of the Windows menu, but has no assigned shortcut. I've tried the following to assign a shortcut to it, but it doesn't add a "⌘L" as I want: Window("Logs", id: "logs") { LogsView() } .keyboardShortcut("l") I can brute-force this using .commands to replace the menu item but that seems crude and unnecessary. Is it the only way?
2
0
499
Jan ’25
Attempt to map database failed
This looks like a refresh of an old question. I'm using iOS 15 beta 7 and have presented a UIActivityViewController from a SwiftUI app. I get a ton of these errors when trying to share a two-item list containing String and UISimpleTextPrintFormatter. [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} [default] Attempt to map database failed: permission was denied. This attempt will not be retried. [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} [default] -imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.) [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} It looks as if the API is checking for entitlements I haven't requested, but I am not trying to share images. I just want to share text as plaintext or a nicely formatted printable attributed string.
4
3
7.4k
Aug ’21
Animate list row height
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)") } } } }
1
4
1.1k
Oct ’23
Define Array of protocol which conforms to Identifiable
I've got Yet Another Protocol Question. Sorry, folks.The Swift 5.1 manual describes creating a `Collection` where the `Element` is a simple protocol, but doesn't explain how to make a Collection where the Element is a protocol with an associatedtype. In my case it's a protocol `Playable` that requires conformance to `Identifiable`.I am fine with requiring the `Identifiable.ID` type to be `Int` for all types which adopt `Playable`, but I don't know how to express that qualification/requirement. The bits hit the fan when I try to declare something to be `[Playable]`.My playground code might make my question clear.protocol Playable: Identifiable // DOESN'T WORK where ID: Int { // DOESN'T HELP associatedtype ID = Int // DOESN'T HELP var id: Int { get } func play() } struct Music: Playable { var id: Int func play() { print("playing music #\(id)") } } (Music(id: 1)).play() // displays: "playing music #1\n" class Game: Playable { var id: Int init(id: Int) { self.id = id } func play() { print("playing game #\(id)") } } (Game(id: 2)).play() // displays: "playing game #2\n" enum Lottery: Int, Playable { case state = 100 case church case charity var id: Int { return self.rawValue } func play() { print("playing lottery \(self) #\(self.rawValue)") } } Lottery.church.play() // displays: "playing lottery church #101\n" var stuff: [Playable] = [] // error: Protocol 'Playable' can only be used as a generic constraint because it has Self or associated type requirements stuff.append(Music(id: 10)) stuff.append(Game(id: 24)) stuff.append(Lottery.charity) stuff.map { $0.id }My goal is to have different structs and classes conforming to Playable (and hence to Identifiable) able to live inside a Collection.
7
1
7.7k
Nov ’22
TextEditor textRange (with AttributedString?)
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.
0
1
1.2k
Jun ’21
Dragging list rows between sections
I am making an iPhone-first app which has a 2 level data structure. I want the user to be able to drag List rows from section to section, but not reorder the sections. Is there a SwiftUI way to do it, or should I resort to UIKit? The basic problem seems to be that ForEach.onMove only allows reordering within its nearest datasource. That seems sensible as a general facility. As it stands now drags can only happen within a section. Swift ForEach(groups) { group in Section(header: Text(group.text)) { ForEach(group.items) { item in Text(item.text) } } } .onMove { … } I might be willing to dive into UIKit to get this done, if it'll handle it. Right now I've flattened the data and marked some items as "containers" and others as "leaves". All get emitted as a dumb flat list: Swift ForEach(items) { item in if item.isContainer { Text(item.text).bold() } else { Text(item.text) } } .onMove { … } The major downside is users can move the container "section header" lines. Drag and drop doesn't seem to work on iPhone, just iPads. I'm kinda shy about hierarchical lists using List(_,children:) because I expect move would still allow top level items (my containers) would be allowed to be moved.
4
0
5.5k
Jul ’21