Post

Replies

Boosts

Views

Activity

Can not access MacOS 15 beta
In Settings->Update the is no option for beta's. I did download the ipsw and do a clean install on beta 1, but I really don't want to have to do another clean install for every beta. I have called tech support, and they checked everything they could and found nothing wrong. I am signed in with my one and only Apple ID. The beta option is not offered in updates. I do not use Time Machine, I use Carbon Copy Cloner instead. Is that a problem? Does my "team" id come into play at all? Those are the only two things I can think of - HELP!
0
0
380
Jul ’24
Timing issue with SwiftUI/SwiftData autosave
I have an issue that is a timing issue. The issue is I have a list: List(sidebars[0].childrenSorted!, id:\.id, children: \.childrenSorted, selection: $selected) { sidebar in It works great for me., as is. I am now implementing add, delete, and move (drag and drop) functionality to the list. The data is persisted in SwiftData, so the order of the array is not maintained, and I have a field called "index," which allows it to be sorted correctly for each display. That also works. If I insert or move an item in the list, I must update the index of all the elements after the insertion point in that "child" (folder) to the new order/sequence number. Here is the code for dropping a row item onto another row item in the same child/folder. (Note: indexes are incremented by 2 to allow for the insertion of new items and reindexing) The dropped item should be placed after the target item: func dropOnSidebarItem(dropped: Sidebar, target: Sidebar) { if target.parent_?.id != dropped.parent_?.id { // moving to new parent dropped.parent_?.children_?.removeAll(where: {$0.id == dropped.id}) dropped.parent_ = target.parent_ target.parent_?.children_?.append(dropped) } dropped.index = target.index + 1 var ix = 0 target.parent_?.childrenSorted?.forEach { child in child.index = ix ix += 2 } } If I run this as is, it will crash at the List statement with a nil access to the sidebars[0]. If I add this after the reindexing loop (above), it runs correctly: target.parent_?.childrenSorted?.forEach { child in print("\(child.title)") } All this addition does is to put a slight delay before returning. That is an obvious HACK doomed to failure at some point. The issue appears to be that the list is updated before the reindexing is complete. I have tried placing the reindexing into a function with a tempModelContext that does not autosave. I then manually save the temporary context once the loop is done - the same failure occurs, and the same "delay" makes it work. Do you have any suggestions on what I am doing wrong? It appears to be associated with autosaving the SwiftData changes. TIA, Frank
1
0
640
Dec ’23
Drag and Drop in Nested List
Does anyone KNOW if SwiftUI now supports drag and drop in a list? It seems like it was only working in ForEach before the latest version. Now, this tries to work, but hangs. List(sidebars.sorted{$0.index < $1.index}[0].children!, id:\.id, children: \.children, selection: $selected) { sidebar in NavigationLink { SidebarDetailSelectorView(sidebar: sidebar) } label: { rowLabel(sidebar: sidebar) //.background(Color.random()) } .onChange(of: selected) { currentSidebar.sidebar = sidebars.first{ $0.id == selected } currentSidebar.editSidebar = currentSidebar.sidebar } .draggable(sidebar) .dropDestination(for: Sidebar.self) { sidebars, location in print("\(sidebars[0].title) -> \(sidebar.title)") return true } } I want a hierarchical sidebar (like finder or mail) to be able to drag and drop within the list to reorder it. I can get it working with DisclosureGroups. The parent items can be dragged or dropped on but are not selectable - which I need. Here is an example of my recursive DisclusureGroup implementation using ForEach loops. struct MenuItemView: View { let item: MenuItem var body: some View { if let children = item.children, children.isEmpty == false { DisclosureGroup(item.text) { ForEach(children, id: \.id) { childItem in MenuItemView(item: childItem) .draggable(childItem) .dropDestination(for: MenuItem.self) { items, location in print("\(items[0].text) -> \(childItem.text)") return true } isTargeted: { isTargeted in item.isTargeted = isTargeted } } } } else { VStack { NavigationLink(item.text, destination: Text(item.text)) .foregroundColor(item.isTargeted ? .teal : Color(.selectedTextColor )) .draggable(item) .dropDestination(for: MenuItem.self) { items, location in print("\(items[0].text) -> \(item.text)") return true } isTargeted: { isTargeted in item.isTargeted = isTargeted } } } } }
1
0
1.1k
Nov ’23
NavigationLink(value:, Label:)
I see this "new" NavigationLink in Apples documentation: Apple NavigationLink I am upgrading my working code from a depreciated NavigationLink with "destination" to a NavigationStack with a value. But, I can not get XCode to accept any syntax I can come up with using a Label (). Here is what I have tried (along with other variations). XCode chokes on this and says it is too complex. NavigationLink( value: sidebar, { Label(sidebar.title, systemImage: SFSymbolsModel.icon[sidebar.type] ?? "questionmark" ) }) I need a Label (I think - it is what I used before) because I want to format the displayed text with an Icon. All of the examples I can find use a string to provide the label. Does "Label" in the documentation not mean an actual Label, like we have in the depreciated version? Can anyone provide me a one- or two-line example of the correct syntax?
2
0
1.1k
Oct ’23
NSFontPanel in SwiftUI
I am trying to get NSFontPanel/NSFontManager to work in a SwiftUI Document Template app. I have the following defined, a customize version of this I found on GitHub. This lets me pick the size, face, style, etc. Interestingly, a color picker is included in the FontPanel. The documentation doesn't seem to say this. Is this something new? Anyway, I would like to either be able to use the color picker to let the user select a color, or if not I would like to hide the color picker - at is not "critical" to this application. I am using this to allow customization of text in a sidebar, so color is nice, but not necessary. Any help would be appreciated. public struct FontPicker: View{     let labelString: String     @Binding var font: NSFont     @State var fontPickerDelegate: FontPickerDelegate?     public init(_ label: String, selection: Binding<NSFont>) {         self.labelString = label         self._font = selection     }    let fontManager = NSFontManager.shared     let fontPanel = NSFontPanel.shared     @AppStorage("setSidebarFont") var setSidebarFont = "System"     @AppStorage("setSidebarFontSize") var setSidebarFontSize = 24     @AppStorage("setSidebarFontColor") var setSidebarFontColor = "gray"     public var body: some View {         HStack {             Text(labelString)             Button {                 if fontPanel.isVisible {                     fontPanel.orderOut(nil)                     return                 }                 self.fontPickerDelegate = FontPickerDelegate(self)                 fontManager.target = self.fontPickerDelegate                 fontManager.action = #selector(fontPickerDelegate?.changeAttributes)                 fontPanel.setPanelFont(self.font, isMultiple: false)                 fontPanel.orderBack(nil)             } label: {                 Text("Font Selection: \(setSidebarFont)")                     .font(.custom(setSidebarFont, size: CGFloat(setSidebarFontSize)))             }         }     }          func fontSelected() {         self.font = fontPanel.convert(self.font)         setSidebarFont = self.font.displayName ?? "System"         setSidebarFontSize = Int(self.font.pointSize)         var newAttributes = fontManager.convertAttributes([String : AnyObject]())         newAttributes["NSForegroundColorAttributeName"] = newAttributes["NSColor"]         newAttributes["NSUnderlineStyleAttributeName"] = newAttributes["NSUnderline"]         newAttributes["NSStrikethroughStyleAttributeName"] = newAttributes["NSStrikethrough"]         newAttributes["NSUnderlineColorAttributeName"] = newAttributes["NSUnderlineColor"]         newAttributes["NSStrikethroughColorAttributeName"] = newAttributes["NSStrikethroughColor"]         print("\(newAttributes["NSForegroundColorAttributeName"]!)")     } }
1
0
971
Jun ’22