Post

Replies

Boosts

Views

Activity

Reply to Printing Objects in Swift
When you want to test a simple expression like print("Hello, World!") on the top level, it needs to be written in a fixed file main.swift, no other file names are allowed. And main.swift would only work with the project template: macOS Command Line Tool. Create a new project macOS Command Line Tool, and edit main.swift. Or if you want to test your code in a GUI app, you need to move the line print("Hello, World!") into some function.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Protocol Not Working
If the transfer works then my sendData() method up top would print a statement but my addToFav only prints "favourite button pressed". Then I guess delegate is nil when sendData() is called. By the way, please follow the simple coding rule of Swift -- type names should start with Capital letter. Your code is hard to read.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to How to activate / deactivate menu items in SwiftUI
What am I missing? Maybe it is caused by some implementation details of the current SwiftUI in the similar way where .sheet cannot handle @State vars. A simple workaround: import SwiftUI @main struct MenuTestApp: App { 		@State var active = false 		var body: some Scene { 				WindowGroup { 						ContentView() 				} 				.commands(content: { 						CommandMenu("Tools", content: { 								Button("Normally active", action: {active = !active}).disabled(active) 								Button("Normally inactive", action: {active = !active}).disabled(!active) 						}) 						CommandGroup(after: .newItem, addition: { 								MyCommandGroup(active: $active) 						}) 				}) 		} } struct MyCommandGroup: View { 		@Binding var active: Bool 		var body: some View { 				Button("Normally active", action: {active.toggle()}).disabled(active) 				Button("Normally inactive", action: {active.toggle()}).disabled(!active) 		} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to How can I press a button from one view and activate sth in another view?
Sorry, bug your description and code are too vague and I do not understand what you really want to do? when users press a button in another view called Play In your code, there is no button in the view Play. I have created a view called Graph  Your Play has a view named ViewGraph inside, is it the same as the view called Graph? a graph is displayed What triggers the graph to be displayed? Can you show the whole code of Graph (or ViewGraph) ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Color set has an unassigned color child.
I can't save the color there next to the appicon in the small color square with the white color, while I set the color(any) to the large Universal squares. Sorry, but as far as I tried, I cannot get the screen you have described. What version of Xcode are you using? Are you sure you have chosen Color Set after pressing the + button at the left bottom? Can you share the screen shot of your Assets editor by any means? (It's a pity this site does not have an image sharing feature yet.)
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’21
Reply to Open files created in iOS Documents folder
As far as I tried, UIDocumentPickerViewController shows the file saved in the Documents directory. (For plist files, "com.apple.property-list" seems to be the right type specifier.) Have you set Info.plist of your app properly? You need to set both UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace to YES.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’21
Reply to tableview.reloadRows() takes three hit to reload
if you know what is the caused that lead me to wrap those methods with DispatchQueue.main.async{} as stated above please let me know hehe Thanks for sharing your experience. But unfortunately, whether enclosing with DispatchQueue.main.async{...} or not does not affect the behavior of my test project, so I have nothing to tell you right now. Please share your info when you find something new, I will be watching on this thread.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21