在Swift 3中将文本追加到NSTextView [英] Appending text to NSTextView in Swift 3

查看:306
本文介绍了在Swift 3中将文本追加到NSTextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用MDM API来对设备属性进行批量更新的应用程序。

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

我希望具有某种可见的输出/登录主视图,以便用户可以看到其CSV的哪些行可能失败以及HTTP响应代码是什么。我可以很容易地附加到 NSTextField 或标签,但是由于可能会有很多行,所以我想有一个可滚动的文本框将信息附加到。

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.

我找到的所有文档似乎都是Swift 2,这是我所缺少的难题之一。

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.

我尝试将我的出口声明为 NSScrollView NSTextView ,并且似乎都没有影响。 insertText 似乎已被弃用。

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.

过去,在Swift 2上,我使用了此解决方案对我来说效果很好,但是在swift 3上不起作用。

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.

推荐答案

我想我已经明白了出来。我进入了视图控制器场景,并深入到了NSScrollView>剪辑视图>文本视图,然后从中创建了我的插座,而不仅仅是手动将其从NSScrollView更改为NSTextView。

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"))

这篇关于在Swift 3中将文本追加到NSTextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆