Append String in Swift

前端 未结 12 1281
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 00:43

I am new to iOS. I am currently studying iOS using Objective-C and Swift.

To append a string in Objective-C I am using following code:

 NSString *str         


        
12条回答
  •  伪装坚强ぢ
    2020-12-03 00:58

    SWIFT 2.x

    let extendedURLString = urlString.stringByAppendingString("&requireslogin=true")
    

    SWIFT 3.0

    From Documentation: "You can append a Character value to a String variable with the String type’s append() method:" so we cannot use append for Strings.

    urlString += "&requireslogin=true"
    

    "+" Operator works in both versions

    let extendedURLString = urlString+"&requireslogin=true"
    

提交回复
热议问题