我一直在嘗試轉換這個代碼,我從這個example(在Objective-c中)沒有運氣。 String *path; // contains the file path
// Get the UTI from the file's extension:
CFStringRef pathExtension = (__bridge_retained CFStringRef)[p
我有一個由單詞組成的字符串,其中一些包含標點符號,我想刪除它,但我一直無法弄清楚如何執行此操作。 例如,如果我有像 var words = "Hello, this : is .. a string?"
我希望能夠創建與 "[Hello, this, is, a, string]"
我原以爲陣列是使用類似words.stringByTrimmingCharactersInSet(),以消除
很多時候,你需要編寫的代碼如下所示: if someOptional != nil {
// do something with the unwrapped someOptional e.g.
someFunction(someOptional!)
}
這似乎有點冗長,而且我聽說使用!力展開運算符可以是不安全的,最好避免。有沒有更好的方法來處理這個問題?