Post

Replies

Boosts

Views

Activity

Reply to Help with showing a spectrogram of an audio file
@MediaEngineer, Sorry for the late reply. I have been trying to upload an image showing my results but it won't let me. The image that I get is mostly yellow and orange dots. I don't really know why this is happening or what steps I should take to try and fix it, but I am sure my code incorrect. Have you been able to successfully create a spectrogram from an audio file before using Swift? Just curious. Thanks!
Oct ’22
Reply to SwiftUI MacOS TableColumn compiler can't type-check expression in reasonable time.
I have run into this issue many times, so I feel your pain! Unfortunately the SwiftUI Table is garbage and the best way to get a table in SwiftUI is to use a NSTableView. I have gone through months of trial and error trying to figure out how to get additional columns and some other features such as movable columns, but it is just a waste of time. I now have an NSTableView that I created using InterfaceBuilder with its view controller wrapped in a NSViewControllerRepresentable and a Coordinator class and it works perfect. I used a NSArrayController with Cocoa Bindings which allowed me to set the table up in Interface Builder with very little code. All you have to do is change your data model, Long Call, into "@objc member class Long Call: NSObject {}" instead of a structure. If you have never used Interface Builder before it may look daunting, but it really isn't. Especially for just a NSTableView, it will save you a lot of time and frustration. There are a few tutorials and gitHub projects that you can find with a google search, as well as some good examples on this forum. If you get stuck let me know and I can help you. I hope this helps!
May ’22
Reply to Is there a way to Show Hide a sidebar with a button?
@MarkErbaugh Sorry for the late reply. Yes, you are correct that there is no native SwiftUI way to accomplish the task. As for a sidebar on the right side, there is a way to accomplish this but it is more complicated. I don't have any code right now that accomplishes it, but in the past I did something similar using a horizontal split view. It would appear and disappear depending on an @State var showRightSidebar = "false" and then I had a button that would toggle that variable to show and hid the view just like you would with a modal or sheet view.
May ’22
Reply to ToolBar
The first thing that you need to do is construct the view properly including the main body. When you first create a new SwiftUI view file, it should look like this: import SwiftUI struct ContentView: View {     var body: some View {         Text("Hello, World!")     } } You can delete the "Text("Hello, World!")" if you do not need it and then you need to construct the view starting with something like a VStack, HStack, List, Table, etc.... Once that is done you can add the toolbar and your buttons. I have no idea how your data and ToDoItems are constructed so I am just guessing about how to import them and display them in a List but your code should look similar to this: import SwiftUI struct ContentView: View { let data: [Data] var body: some View { List(data id: \.self) { item in Text(item) } .toolbar { ToolbarItem(placement: .primaryAction) { Button(action: {                     data.data.append(TodoItem())                 }, label: {                     Image(systemName: "plus")                 }) } ToolbarItem(placement: .automatic) { Button("Filter") {} } } } }
May ’22
Reply to Is there a way to Show Hide a sidebar with a button?
Hey, You can add the button to the toolbar window using the following code after a list. The toolbar item placement is set to ".automatic", which is what causes the button to appear in the sidebar toolbar like in Xcode. .toolbar { ToolbarItem(placement: .automatic) { Button(action: toggleSidebar, label: { Image(systemName: "sidebar.leading") }) } Then you need to add "toggleSidebar" function, which is:   #if os(iOS)   #else NSApp.sendAction(#selector(NSSplitViewController.toggleSidebar(_:)), to: nil, from: nil)   #endif } } All together you get something like this: var body: some View { List { NavigationLink(destination: ...) NavigationLink(destination: ...) NavigationLink(destination: ...) }.listStyle(SidebarListStyle()) .toolbar { ToolbarItem(placement: .automatic) { Button(action: toggleSidebar, label: { Image(systemName: "sidebar.leading") }) } }.navigationTitle("Search") } private func toggleSidebar() {   #if os(iOS)   #else NSApp.sendAction(#selector(NSSplitViewController.toggleSidebar(_:)), to: nil, from: nil)   #endif } } Don't mind the empty NavigationLinks in the list, they are just for example. The contents of the list do not really matter as long as the list works Hope this helps
May ’22
Reply to In SwiftUI how to ask user to save edits when dismissing a NavigationLink
Without any code I can't know for sure if this will work but I just tried this in my MacOS app, which has a detail view appear in a sheet modal, and it works. In my detail view I also have a button that calls a save function. To dismiss my detail view I have the following button: Button(action: { dismiss() }, label: { Text("Back") }) All I needed to do is add a call to my save function above "dismiss()" Button(action: { FileManager().saveText(infoText!) dismiss() }, label: { Text("Back") }) Now when I hit the button to dismiss my detail view my save function runs, which shows a save dialog, and when I hit the "Save" button in the dialog it saves the file and then the detail view closes. I hope this helps!
Mar ’22
Reply to How to move title from left to right
There are a couple of ways of doing it depending on what you want to do with the rest of the view. One way to do it would be to add a navigation bar title instead of a navigation title like this:   var body: some View {     NavigationView {       ZStack {         LinearGradient(gradient: /*@START_MENU_TOKEN@*/Gradient(colors: [Color.red, Color.blue])/*@END_MENU_TOKEN@*/, startPoint: /*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/, endPoint: /*@START_MENU_TOKEN@*/.trailing/*@END_MENU_TOKEN@*/)       }       .navigationBarItems(trailing: Text("בית"))       .navigationBarTitle(Text(""), displayMode: .inline)       .edgesIgnoringSafeArea(.all)       .opacity(0.3)     }   } } or you can change the environment of the navigation view so that text on the left side will show on the right side like this:   var body: some View {     NavigationView {       ZStack {         LinearGradient(gradient: /*@START_MENU_TOKEN@*/Gradient(colors: [Color.red, Color.blue])/*@END_MENU_TOKEN@*/, startPoint: /*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/, endPoint: /*@START_MENU_TOKEN@*/.trailing/*@END_MENU_TOKEN@*/)       }       .navigationTitle("בית")       .edgesIgnoringSafeArea(.all)       .opacity(0.3)     }.environment(\.layoutDirection, .rightToLeft)   } } This method will cause all mostly everything to start on the right side though. This may be good or bad depending on what else will be in the view. Hopefully one of these options will help.
Feb ’22
Reply to SwiftUI Mac OS toolbar at top of sheet window?
Hi @Apple_Kevin thanks for answering! I am a little confused though. Are you saying that if I created my app first as an iPad app and then converted it to a macOS app that the toolbar would appear at the top of the window in the MacOS app created with catalyst? But that I cannot get the same result building a native macOS app? Why would design guidelines be different for each app when running on macOS? thanks!
Jan ’22
Reply to Having trouble getting MusicKit Data into my SwiftUI view
@JoeKun, no problem, that makes sense and I completely understand! As always, thanks for taking the time to respond and thanks again for all of your help with MusicKit! p.s. in case you are ever wondering what items could be added to improve MusicKit, it would be great if MusicKit could include song/track BMP, and the Artist Bio information seen in Apple Music, including birth date and where they are from. Lyrics would be a game changer 😉.
Jan ’22
Reply to Having trouble getting MusicKit Data into my SwiftUI view
Hi @JoeKun, So I have seen a couple of questions, including mine(https://developer.apple.com/forums/thread/697719), regarding the use of .onTapGesture on a Table Row. Could you please take a look at that? basically I want to be able to double click a row and have that open a new view. Currently it seems that this will only work on text in the row. We need to be able to double click anywhere in the row, similar to how you can select a row by clicking on it anywhere. Next is the issue is that, and toolbars will only appear at the bottom of the screen and not the top. I have seen many unanswered help requests regarding this subject and I will post mine as well, but is this intentional? or is this a bug? I even took code directly from the apple developer documentation on toolbars, which shows a toolbar at the top of the screen, but when I ran it in Xcode the toolbar goes to the bottom. Thanks so much!
Jan ’22
Reply to How to get the output of a for-in loop into a single DataFrame instead of many Dataframes
@JoeKun, Thanks so much for the detailed reply! Again, you are a life saver! @MobileTen, Thanks for help on this too! I had actually tried your method, except that I can't write out the tracks' names and other details since I do not know what is being returned in the MusicItemCollection for each search. It's a good idea and should work, but while the Encoding of MusicItemCollection to a JSON works, when I tried to use the json for the DataFrame I would get errors about the json not being formatted properly because "the top level is not a sequence". Strange, huh? Happy New Year to you both!
Jan ’22
Reply to is it possible to use gestures with SwiftUI Table?
Hey @MobileTen, Thanks for responding! I appreciate the help. I should have made myself clearer though in that I want to be able to double click anywhere in the row and not just the text in a certain column. Or at least anywhere in the cell containing the text. Any other ideas on how I could possible make this work? Thanks again!
Jan ’22