首页 > 编程语言 > 详细

Swift -- 组合赋值运算符

时间:2015-12-12 12:26:56      阅读:146      评论:0      收藏:0      [点我收藏+]

struct CenterPointer{

    var x = 0, y = 0

}

func + (left:CenterPointer, right:CenterPointer) -> CenterPointer{

    return CenterPointer(x:left.x + right.x, y:left.y + right.y)

}

let zPointer = CenterPointer(x:2, y:3)

let yPointer = CenterPointer(x:5, y:3)

let xPointer = zPointer + yPointer

prefix func - (cPointer:CenterPointer) -> CenterPointer{

    return CenterPointer(x:-cPointer.x, y:-cPointer.y)

}

let zzPointer = CenterPointer(x:2, y:3)

let yyPointer = -zPointer

func += (inout left:CenterPointer, right: CenterPointer){

    left = left + right

}

var zzzPointer = CenterPointer(x:2, y:1)

zzzPointer += zzzPointer

func == (left:CenterPointer, right:CenterPointer) -> Bool{

    return (left.x == right.x) && (left.y == right.y)

}

func != (left:CenterPointer, right:CenterPointer) -> Bool{

    return !(left == right)

Swift -- 组合赋值运算符

原文:http://www.cnblogs.com/lianfu/p/5041021.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!