2

I am building an application that utilizes an MDM API to make bulk updates to attributes of devices.

I am looking to have some sort of visible output/logging in the main view so that the user can see what lines of their CSV may have failed and what the HTTP Response Code was. I can append to an NSTextField or a label easy enough, but seeing as how there may be a large output with many lines, I'd like to have a scrollable text box to append the information to.

All of the documentation that I've found for doing this seems to be Swift 2, and this is the one piece of the puzzle I'm missing.

Alternatively, if there's a better way to display some sort of logging output on the main screen, I'd be open to that as well.

I've tried declaring my outlet as both an NSScrollView and an NSTextView, and neither seems to make a difference. insertText seems to be deprecated.

In the past, on Swift 2 I've used this solution and it worked well for me, but it doesn't work on swift 3.

Community
  • 1
  • 1
Mike Levenick
  • 183
  • 2
  • 12

1 Answers1

15

I think I got this figured out. I went into the view controller scene and drilled down into the NSScrollView > Clip View > Text View and then created my outlet out of that instead of just manually changing it from NSScrollView to NSTextView.

Once I did that, the following line did me just fine:

myTxtView.textStorage?.append(NSAttributedString(string: "Hello World"))
Mike Levenick
  • 183
  • 2
  • 12
  • no idea if that matters: I additionally had to set the width of the documentView of the enclosing ScrollView to eg. 2000 to get the desired result of a horizontally scrollable Field without linebreaks in the ScrollView's visible Field. – heimi Jul 03 '17 at 09:16