Post

Replies

Boosts

Views

Activity

Reply to Presentation single with code
Every time the user clicks the button the same window opens again and again. How to avoid that? It is not clear what you want to do. But I guess you just want to activate the window if it is already opened. Then, you should not instantiate a new instance at each time: private var controller: NSWindowController? = { let storyboard:NSStoryboard = NSStoryboard(name: "Main", bundle: nil) return storyboard.instantiateController(withIdentifier: "finestra3") as? NSWindowController }() @IBAction func obrirAmbCodi(_ sender: NSButton) { controller?.showWindow(self) }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to Limit width of wheel style picker on iOS
I do not know why this works, but an answer in an SO thread would work for you. Picker("", selection: Binding( get: { value }, set: { val in updateModel(val, pos) }) ) { ForEach(0 ..< 10, id: \.self) { i in Text("\(i)") } } .pickerStyle(.wheel) .labelsHidden() .frame(width: 20) .frame(idealHeight: height, maxHeight: .infinity) .clipped() .compositingGroup() //<-
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to How to designate principal class
According to the documentation, you need to add a device activity monitor extension to your app, and then you can designate the subclass as the principal class by editing the Info.plist of the extension. Unfortunately, there is no template for device activity monitor extension in the latest Xcode (15 beta 5) nor any documentations in the dev site of Apple's and you need to explore the world wide web to accomplish it.
Topic: App & System Services SubTopic: General Tags:
Aug ’21
Reply to @AppStorage with Date in SwiftUI
Is there a better way to save Date in @AppStorage?  One possible solution: extension Date: RawRepresentable { public var rawValue: Double { self.timeIntervalSinceReferenceDate } public init?(rawValue: Double) { self = Date(timeIntervalSinceReferenceDate: rawValue) } } (UPDATE) I want to be able to initialize it like this @AppStorage("date") var date = Date() Sorry, I was missing that Int or String is needed for automatic conversion. Please try this: extension Date: RawRepresentable { public var rawValue: String { self.timeIntervalSinceReferenceDate.description } public init?(rawValue: String) { self = Date(timeIntervalSinceReferenceDate: Double(rawValue) ?? 0.0) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to Need Help Transfer Data From Button
Okay I can give you the favcell code it's a custom cell, the segue to HighlightsVC is put where the button is. Thanks for showing your code and clarifying. I'm also counting on this: I have to get rid of the button action and do a segue with storyboard. As you are connecting the segue from the button, insisting on using tableView(_:willSelectRowAt:) does not make sense and you can remove it. Please try the following prepare(for:sender:) and tell us what you get. override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "hs" { print("this is the segue destination: \(segue.destination)") if let button = sender as? UIButton { var currentView: UIView = button while let parentView = currentView.superview { if let cell = parentView as? FavCell { let selectedNameInCell = cell.name.text print("name being transferred is \(selectedNameInCell)") if let destinationController = segue.destination as? HighlightsVC, let destName = selectedNameInCell { destinationController.playerName = destName } break } currentView = parentView } } else { print("The segue is not from UIButton") } } }
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Reply to @AppStorage with Date in SwiftUI
Your #1 is locale-dependent. When user change the Language settings of the device, the saved date would not be able to be retrieved. Also, it lacks time information. Your #2 lacks sub-second information. Re-read value may not be exactly the same as was when saved.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to View body is called although its @Binding has not changed
we’d expect that its body is called when the value changes. Unfortunately, that is a wrong expectation. SwiftUI may call body at any time needed, for example any of the @State variables of the outer view change. Is there any way to avoid this behaviour that can ultimately lead to performance issues? You may need to construct your views as will not lead performance issues, or you can go back to UIKit world.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to Title and Description ShareSheet
You may use UIActivityItemSource with LPLinkMetadata. Prepare a class inheriting UIActivityItemSource somewhere in your project: import LinkPresentation class MyActivityItemSource: NSObject, UIActivityItemSource { var title: String var text: String init(title: String, text: String) { self.title = title self.text = text super.init() } func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { return text } func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { return text } func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String { return title } func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? { let metadata = LPLinkMetadata() metadata.title = title metadata.iconProvider = NSItemProvider(object: UIImage(systemName: "text.bubble")!) //This is a bit ugly, though I could not find other ways to show text content below title. //https://stackoverflow.com/questions/60563773/ios-13-share-sheet-changing-subtitle-item-description //You may need to escape some special characters like "/". metadata.originalURL = URL(fileURLWithPath: text) return metadata } } And use it like this: let title = "Jokes Are Us Diagnostics:" let text = "Some Text" // set up activity view controller let textToShare: [Any] = [ MyActivityItemSource(title: title, text: text) ] let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil) activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash // exclude some activity types from the list (optional) activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop ] // present the view controller self.present(activityViewController, animated: true, completion: nil) As far as I tried, this may not produce the expected result if you add other items into textToShare.
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’21