亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Xcode 7.3已棄用“ ++”和“-”運算符

Xcode 7.3已棄用“ ++”和“-”運算符

子衿沉夜 2019-11-28 09:43:15
我正在查看Xcode 7.3注釋,并且注意到了這個問題。++和-運算符已被棄用有人可以解釋為什么不推薦使用它嗎?我說對了,現在在新版本的Xcode中,您將使用它代替++它x += 1;例:for var index = 0; index < 3; index += 1 {    print("index is \(index)")}
查看完整描述

3 回答

?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

我意識到,盡管如此,此評論仍未解決問題,可能有人會在尋找一種解決方案,以使這些操作員保持工作狀態,這種解決方案可以在底部找到。?


我個人更喜歡++和--運營商。我不同意它們棘手或難以管理的觀點。一旦開發人員了解了這些運算符的功能(并且我們正在談論非常簡單的內容),則代碼應該非常清楚。


在解釋為什么不推薦使用運算符時,提到了它們的主要用途是C風格的for循環。我對其他人一無所知,但我個人根本不使用C風格的循環,在還有其他地方或情況下,++或--運算符是有用的。


我還要提及的是,它varName++返回一個值,因此可以在returnwhile中使用它,而varName += 1不能在其中使用。


對于任何想讓這些操作員在這里工作的人,解決方案是:


prefix operator ++ {}

postfix operator ++ {}


prefix operator -- {}

postfix operator -- {}



// Increment

prefix func ++(inout x: Int) -> Int {

    x += 1

    return x

}


postfix func ++(inout x: Int) -> Int {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: UInt) -> UInt {

    x += 1

    return x

}


postfix func ++(inout x: UInt) -> UInt {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: Int8) -> Int8 {

    x += 1

    return x

}


postfix func ++(inout x: Int8) -> Int8 {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: UInt8) -> UInt8 {

    x += 1

    return x

}


postfix func ++(inout x: UInt8) -> UInt8 {

    x += 1

    return (x - 1)

}

prefix func ++(inout x: Int16) -> Int16 {

    x += 1

    return x

}


postfix func ++(inout x: Int16) -> Int16 {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: UInt16) -> UInt16 {

    x += 1

    return x

}


postfix func ++(inout x: UInt16) -> UInt16 {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: Int32) -> Int32 {

    x += 1

    return x

}


postfix func ++(inout x: Int32) -> Int32 {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: UInt32) -> UInt32 {

    x += 1

    return x

}


postfix func ++(inout x: UInt32) -> UInt32 {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: Int64) -> Int64 {

    x += 1

    return x

}


postfix func ++(inout x: Int64) -> Int64 {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: UInt64) -> UInt64 {

    x += 1

    return x

}


postfix func ++(inout x: UInt64) -> UInt64 {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: Double) -> Double {

    x += 1

    return x

}


postfix func ++(inout x: Double) -> Double {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: Float) -> Float {

    x += 1

    return x

}


postfix func ++(inout x: Float) -> Float {

    x += 1

    return (x - 1)

}


prefix func ++(inout x: Float80) -> Float80 {

    x += 1

    return x

}


postfix func ++(inout x: Float80) -> Float80 {

    x += 1

    return (x - 1)

}


prefix func ++<T : _Incrementable>(inout i: T) -> T {

    i = i.successor()

    return i

}


postfix func ++<T : _Incrementable>(inout i: T) -> T {

    let y = i

    i = i.successor()

    return y

}


// Decrement

prefix func --(inout x: Int) -> Int {

    x -= 1

    return x

}


postfix func --(inout x: Int) -> Int {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: UInt) -> UInt {

    x -= 1

    return x

}


postfix func --(inout x: UInt) -> UInt {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: Int8) -> Int8 {

    x -= 1

    return x

}


postfix func --(inout x: Int8) -> Int8 {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: UInt8) -> UInt8 {

    x -= 1

    return x

}


postfix func --(inout x: UInt8) -> UInt8 {

    x -= 1

    return (x + 1)

}

prefix func --(inout x: Int16) -> Int16 {

    x -= 1

    return x

}


postfix func --(inout x: Int16) -> Int16 {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: UInt16) -> UInt16 {

    x -= 1

    return x

}


postfix func --(inout x: UInt16) -> UInt16 {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: Int32) -> Int32 {

    x -= 1

    return x

}


postfix func --(inout x: Int32) -> Int32 {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: UInt32) -> UInt32 {

    x -= 1

    return x

}


postfix func --(inout x: UInt32) -> UInt32 {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: Int64) -> Int64 {

    x -= 1

    return x

}


postfix func --(inout x: Int64) -> Int64 {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: UInt64) -> UInt64 {

    x -= 1

    return x

}


postfix func --(inout x: UInt64) -> UInt64 {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: Double) -> Double {

    x -= 1

    return x

}


postfix func --(inout x: Double) -> Double {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: Float) -> Float {

    x -= 1

    return x

}


postfix func --(inout x: Float) -> Float {

    x -= 1

    return (x + 1)

}


prefix func --(inout x: Float80) -> Float80 {

    x -= 1

    return x

}


postfix func --(inout x: Float80) -> Float80 {

    x -= 1

    return (x + 1)

}


prefix func --<T : BidirectionalIndexType>(inout i: T) -> T {

    i = i.predecessor()

    return i

}


postfix func --<T : BidirectionalIndexType>(inout i: T) -> T {

    let y = i

    i = i.predecessor()

    return y

}


查看完整回答
反對 回復 2019-11-28
  • 3 回答
  • 0 關注
  • 675 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號