The swift operator can be defined by itself, simply by adding a simple marker.
@infix the middle operation. such as +,-, *,/operations
@prefix the predecessor operation. such as
@postfix the post-operation. a++, a--
@assignment assignment operation. + =,-=,--a, ++a
main.swift//swiftbasic////Created by Yao_yu on 14-7-27.//Copyright (c) 2014 Yao_yu. All rights Reserved.//import foundationstruct vector2d{var x = 0.0, y = 0.0} @infix func + (a:vector2d, b:vector2d)-> ; vector2d{return vector2d (x:a.x + b.x, Y:A.Y + b.y)} @infix func-(a:vector2d, b:vector2d), vector2d{return a +-B} @prefix func-(a:vector2d)-vector2d{return vector2d (x:-a.x, Y:-a.y)} @assignment func + = (inout a:vecto R2D, b:vector2d) {a = a + b} @prefix @assignment func + + (inout a:vector2d) {++a.x ++a.y} @postfix func + + (a:vector 2D)-vector2d{return a + vector2d (x:1, Y:1)} @infix func = = (a:vector2d, b:vector2d), bool{return (a.x = = b.x) && (a.y = = b.y)} @infix func! = (a:vector2d, b:vector2d), bool{return! ( A = = b)}func vector2d_test () {var a = vector2d (X:1, y:2), B = vector2d (X:3, y:5) var C = A + b A + = b prin TLN ("(\ (c.x), \ (C.Y))") println ("(\ (a.x), \ (A.Y))") assert (A = = C, "a = = B Failed ") A + = B assert (A! = C," A! = B failed ") C = a++ println (" (\ (a.x), \ (A.Y)) ") println (" (\ (c.x), \ (C.Y)) ") }vector2d_test ()