{"id":558,"date":"2023-02-25T19:03:43","date_gmt":"2023-02-25T11:03:43","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=558"},"modified":"2023-04-29T20:36:28","modified_gmt":"2023-04-29T12:36:28","slug":"swift-operator-overloading-and-operator-functions","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/swift-operator-overloading-and-operator-functions\/","title":{"rendered":"Swift &#8211; \u8fd0\u7b97\u7b26\u91cd\u8f7d\u548c\u8fd0\u7b97\u7b26\u51fd\u6570"},"content":{"rendered":"<blockquote>\n<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4<\/p>\n<\/blockquote>\n<p>\u8ba9\u5df2\u6709\u7684\u8fd0\u7b97\u7b26\u5bf9\u81ea\u5b9a\u4e49\u7684\u7c7b\u548c\u7ed3\u6784\u8fdb\u884c\u8fd0\u7b97\u6216\u8005\u91cd\u65b0\u5b9a\u4e49\u5df2\u6709\u8fd0\u7b97\u7b26\u7684\u8fd0\u7b97\u89c4\u5219\uff0c\u8fd9\u79cd\u673a\u5236\u88ab\u79f0\u4e3a\u8fd0\u7b97\u7b26\u91cd\u8f7d\u3002<\/p>\n<h3>\u91cd\u8f7d\u52a0\u53f7\u8fd0\u7b97\u7b26<\/h3>\n<p><!-- more --><\/p>\n<p>\u4f7f\u81ea\u5b9a\u4e49\u7684\u4e24\u4e2a\u5750\u6807\u7ed3\u6784\u4f53\u5bf9\u8c61\u5b9e\u73b0\u76f8\u52a0<\/p>\n<pre><code class=\"language-swift\">struct CenterPointer {\n    var x=0, y=0\n}\n\nfunc + (left:CenterPointer, right:CenterPointer) -&gt; CenterPointer{\n    return CenterPointer(x:left.x+right.x, y:left.y+right.y)\n}\n\nlet pointer1 = CenterPointer(x:2, y:3)\nlet pointer2 = CenterPointer(x:4, y:5)\nlet pointer3 = pointer1 + pointer2<\/code><\/pre>\n<h3>\u91cd\u8f7d\u5224\u65ad\u8fd0\u7b97\u7b26<\/h3>\n<p>\u5b9e\u73b0\u5224\u65ad\u81ea\u5b9a\u4e49\u7c7b\u578b\u662f\u5426\u76f8\u7b49<\/p>\n<pre><code class=\"language-swift\">func == (left:CenterPointer, right:CenterPointer) -&gt; Bool {\n    return (left.x == right.x) &amp;&amp; (left.y == right.y)\n}\n\nfunc != (left:CenterPointer, right:CenterPointer) -&gt; Bool {\n    return !(left == right)\n}<\/code><\/pre>\n<h3>\u91cd\u8f7d\u7ec4\u5408\u8fd0\u7b97\u7b26<\/h3>\n<p>\u5c06\u5176\u4ed6\u8fd0\u7b97\u7b26\u548c\u8d4b\u503c\u8fd0\u7b97\u7b26\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u6ce8\u610f\u8981\u628a\u8fd0\u7b97\u7b26\u5de6\u53c2\u6570\u8bbe\u7f6e\u6210inout\u7c7b\u578b<\/p>\n<pre><code class=\"language-swift\">func += (left:inout CenterPointer, right:CenterPointer){\n    left = left + right\n}\n\nvar pointer1 = CenterPointer(x:2, y:3)\nvar pointer2 = CenterPointer(x:4, y:5)\npointer1 += pointer2<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4 \u8ba9\u5df2\u6709\u7684\u8fd0\u7b97\u7b26\u5bf9\u81ea\u5b9a\u4e49\u7684\u7c7b\u548c\u7ed3\u6784\u8fdb\u884c\u8fd0\u7b97\u6216\u8005\u91cd\u65b0\u5b9a\u4e49\u5df2\u6709\u8fd0\u7b97\u7b26\u7684\u8fd0\u7b97\u89c4\u5219\uff0c\u8fd9\u79cd\u673a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[171],"tags":[],"class_list":["post-558","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=558"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/558\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}