Using Xcode Playground captureValue()

被刻印的时光 ゝ 提交于 2019-12-24 01:16:51

问题


I'm using Playgrounds in Xcode 7.1 (beta 3) but having trouble with the captureValue() function:

captureValue:withIdentifier: Captures a value to be displayed with the specified identifier in the timeline.

Declaration

public func captureValue(value: T, withIdentifier identifier: String)

— Apple Developer Site

When I call the function, all I get is this:

How do I use captureValue? Or is this a bug in beta 3?


回答1:


captureValue() displays the value you capture in the Timeline, which is a separate view that shows up in a playground's Assistant Editor. (You can show the Assistant Editor by pressing Command-Option-Return.) What you're showing is the result of the current line, which, since captureValue() returns Void, is just the XCPlaygroundPage itself.

Here's what the Timeline should look like:




回答2:


However, if you want to have a nice plot in playground instead of a dump list, you'll need to assign CaptureValue in a loop.

for var i in 1...12 {
    XCPlaygroundPage.currentPage.captureValue(i*i*i, withIdentifier: "Cube")
}

Xcode 7.2



来源:https://stackoverflow.com/questions/33262228/using-xcode-playground-capturevalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!