Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get stringValue from a NSTextView

I am creating a OSX Cocoa Application using Swift. I am trying to get the input from a NSTextView to my paste board.

@IBOutlet var issues: NSTextView!

@IBAction func button(_ sender: Any) {
    let stringvalue = "Issue: \(issues.StringValue)"
    let pasteboard = NSPasteboard.general()
    pasteboard.declareTypes([NSPasteboardTypeString], owner: nil)               
    pasteboard.setString(stringvalue, forType: NSPasteboardTypeString)
}

The only error that I am getting is "Value of type 'NSTextView' has no member 'stringValue'.

I don't want to use NSTextField since that only lets me use one line.

like image 473
Brenny Avatar asked Apr 05 '26 19:04

Brenny


1 Answers

NSTextView is a subclass of the NSText class. So you need to get your string using NSText string property:

if let string = issues.string {
    let stringvalue = "Issue: \(string)"
    print(stringvalue)
}
like image 94
Leo Dabus Avatar answered Apr 08 '26 11:04

Leo Dabus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!