1
现在我使用上面的代码来设置一个可选的空字符串,如果它是零,并打开它,如果它有一个值。这只是三行代码,但这对我来说是一个非常常见的操作,所以我想知道是否有更优雅的方式来做到这一点?如何设置为零的可选项为空字符串?
var notesUnwrapped:String = ""
if(calendarEvent.notes != nil){
notesUnwrapped = calendarEvent.notes!
}
使用'如果let'。这里解释:https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID330 – Moritz
你真的应该读语言指南。 – Alexander