是不是将变量显示为字符串?

时间:2015-10-20 04:04:02

标签: ios swift twitter clipboard pasteboard

我已经创建了一个小应用程序来使用swift在IOS上获取剪贴板,但是当我尝试发布变量时,它没有显示为字符串,它显示为

<UILabel: 0x146db1a30; frame = (78.6667 229; 257 147); text = 'I'm on my way right now'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x146db1fd0>>

而不是

\(clipText)

我必须获取剪贴板内容的代码是

let pasteboardString:String? = UIPasteboard.generalPasteboard().string
clipText.text = pasteboardString`

当我使用此代码发布推文时

let tweetController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
tweetController.setInitialText("Here's what was on my clipboard:(clipText)")

我从顶部获取文字。

Image of the code I get instead of (clipText)

1 个答案:

答案 0 :(得分:1)

let pasteboardString:String? = UIPasteboard.generalPasteboard().absolutString
clipText.text = "\(pasteboardString)"

但是你不需要发布UILabel消息是正确的,因为你试图发布UILabel对象。而不是尝试仅发布字符串或UILabel的文本

而不是"\(clipText)"使用"\(clipText.text)"