Xcode Playground 只能部分運行 (Xcode Playground can only run partially)


問題描述

Xcode Playground 只能部分運行 (Xcode Playground can only run partially)

如上所示,在 Xcode 操場上,我正在嘗試擴展協議 Exercise 以獲得另外兩個計算屬性,caloriesBurnedPerMinute描述。當我想在操場上運行這部分代碼時,最左下角的“播放按鈕”顯示為灰色,表示直到第20行才能運行代碼。但是,如果我只想運行代碼直到第14行,如下圖,“播放按鈕”顯示為藍色,表示可以運行代碼到第14行。

here.

It's a way of running your code line by line, but there are some limitations. If you hover over the line number "20", you will see a grey line:

enter image description here

That means Xcode can't only run that part of the code, presumably because how Xcode handles extension declarations.

Just add some code that actually runs, as opposed to just declarations, and press the play button above the bottom panel. Your code will run just fine.

方法 2:

You need to wrap the Double variables in a String cast like String(caloriesBurned):

extension Exercise {
   var description: String {
      return "Exercise(\(name), burned \(String(caloriesBurned)) calories in \(String(minutes)) minutes)"
   }
}

I don't know why, but it helps

(by qsmySweepercyber‑bot)

參考文件

  1. Xcode Playground can only run partially (CC BY‑SA 2.5/3.0/4.0)

#XCode #swift #swift-protocols






相關問題

卸載 xcode 4.5 (iOS 6) (Uninstall xcode 4.5 (iOS 6))

uitextview 字體不隨 fontWIthName 改變 (uitextview font not changing with fontWIthName)

如何將以下行添加到我的 plist 文件中? (How can I add the following lines to my plist file?)

XCode 4.6 顯示方法 + (void)beginAnimations:(NSString *)animationID context:(void *)context; 的內存洩漏警告 (XCode 4.6 shows a warning of memory leak for method + (void)beginAnimations:(NSString *)animationID context:(void *)context;)

iPhone SDK:檢查 UITableView 中每個對象的 ID 號並相應地更改徽章號 (iPhone SDK: Checking the ID number for each object in a UITableView and change the badge number accordingly)

畫面區域的選擇 (Selection of screen area)

如何更改主視圖是基於導航的應用程序! (how to change main view is navigation based app!)

Cocos2d 中的粒子碰撞檢測 (Collision detection with particles in Cocos2d)

Xcode Playground 只能部分運行 (Xcode Playground can only run partially)

如何為collectionviewcell的刪除自定義動畫? (How to custom animation for collectionviewcell's deletion?)

將 2 位整數分配給 char 變量 (Assigning a 2 digit integer to a char variable)

Xcode 12.5 (12E262) 在將 .scn 文件添加到 ARKit 項目後,“Command CodeSign 失敗,退出代碼為非零” (Xcode 12.5 (12E262) "Command CodeSign failed with a nonzero exit code" after a .scn file added to ARKit project)







留言討論