在操场上摆脱额外的输出
Get rid off extra output in playground
我目前正在学习 swift,所以我在 swift 游乐场和 xcode 一起工作。
我正在使用 类,但我得到了一些额外的输出,这让我有点分心。
不知道是我修改了xcode偏好还是我的代码有问题
//: Playground - noun: a place where people can play
import UIKit
class Person {
var name = ""
}
class BlogPost {
var title:String?
var body = ""
var author:Person!
var numberOfComments = 0
}
let post = BlogPost()
if let actualTitle = post.title {
}
我只想摆脱 __lldb_expr_114。
添加 description
属性:
var description : String {
return "BlogPost \(author) - \(title)"
}
使用面向协议的方法:
import Foundation
import Swift
protocol PlaygroundFriendlyClass: CustomStringConvertible
{
}
extension PlaygroundFriendlyClass
{
var description: String
{
return String(describing: type(of: self)).components(separatedBy: ".").last!
}
}
class Foo: PlaygroundFriendlyClass
{
init()
{
}
}
class Bar: PlaygroundFriendlyClass
{
init()
{
}
}
Foo() // "Foo"
Bar() // "Bar"
我目前正在学习 swift,所以我在 swift 游乐场和 xcode 一起工作。
我正在使用 类,但我得到了一些额外的输出,这让我有点分心。
不知道是我修改了xcode偏好还是我的代码有问题
//: Playground - noun: a place where people can play
import UIKit
class Person {
var name = ""
}
class BlogPost {
var title:String?
var body = ""
var author:Person!
var numberOfComments = 0
}
let post = BlogPost()
if let actualTitle = post.title {
}
我只想摆脱 __lldb_expr_114。
添加 description
属性:
var description : String {
return "BlogPost \(author) - \(title)"
}
使用面向协议的方法:
import Foundation
import Swift
protocol PlaygroundFriendlyClass: CustomStringConvertible
{
}
extension PlaygroundFriendlyClass
{
var description: String
{
return String(describing: type(of: self)).components(separatedBy: ".").last!
}
}
class Foo: PlaygroundFriendlyClass
{
init()
{
}
}
class Bar: PlaygroundFriendlyClass
{
init()
{
}
}
Foo() // "Foo"
Bar() // "Bar"