{"id":49,"date":"2021-09-16T14:59:02","date_gmt":"2021-09-16T06:59:02","guid":{"rendered":"https:\/\/yomisoft.com\/?p=49"},"modified":"2023-09-01T10:05:54","modified_gmt":"2023-09-01T02:05:54","slug":"swift5-0%e7%b2%be%e7%ae%80%e7%ac%94%e8%ae%b0-%e7%ac%ac5%e7%ab%a0-if%e8%af%ad%e5%8f%a5%e3%80%81%e5%8f%af%e9%80%89%e7%b1%bb%e5%9e%8b%e7%bb%91%e5%ae%9a%e3%80%81%e9%9a%90%e5%bc%8f%e5%b1%95%e5%bc%80","status":"publish","type":"post","link":"https:\/\/www.yomisoft.com\/index.php\/2021\/09\/16\/swift5-0%e7%b2%be%e7%ae%80%e7%ac%94%e8%ae%b0-%e7%ac%ac5%e7%ab%a0-if%e8%af%ad%e5%8f%a5%e3%80%81%e5%8f%af%e9%80%89%e7%b1%bb%e5%9e%8b%e7%bb%91%e5%ae%9a%e3%80%81%e9%9a%90%e5%bc%8f%e5%b1%95%e5%bc%80\/","title":{"rendered":"Swift5.0\u7cbe\u7b80\u7b14\u8bb0-\u7b2c5\u7ae0-if\u8bed\u53e5\u3001\u53ef\u9009\u7c7b\u578b\u7ed1\u5b9a\u3001\u9690\u5f0f\u5c55\u5f00"},"content":{"rendered":"<p>swift\u4e2d\u7684if\u8bed\u53e5\u548c\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u7684if\u8bed\u53e5\uff0c\u5728\u7528\u6cd5\u548c\u5199\u6cd5\u4e0a\uff0c\u51e0\u4e4e\u5b8c\u5168\u4e00\u6837\u3002<br \/>\n\u53ea\u662fSwift\u4e2d\u7684if\u8bed\u53e5\u540e\u9762\u5c0f\u62ec\u53f7\u53ef\u4ee5\u4e0d\u7528\u5199\uff0c\u4f46\u662f\u6211\u4e00\u822c\u90fd\u5199\u3002<\/p>\n<pre class=\"hl\"><code class=\"\">var a = 10\nif a &lt; 20 {\n   print(\"a\u5c0f\u4e8e20\")\n}else if a &gt; 20 {\n   print(\"a\u5927\u4e8e20\")\n}else{\n   print(\"a\u7b49\u4e8e20\")\n}\nvar b = 30\nif (b &lt; 20) {\n   print(\"b\u5c0f\u4e8e20\")\n}else if (b &gt; 20) {\n   print(\"b\u5927\u4e8e20\")\n}else{\n   print(\"b\u7b49\u4e8e20\")\n}\n\/*\n*\u7f16\u8bd1\u5668\u6253\u5370\u7ed3\u679c\uff1a\na\u5c0f\u4e8e20\nb\u5927\u4e8e20\n*\/<\/code><\/pre>\n<p>\u4e0b\u9762\u662f\u5173\u4e8eif\u8bed\u53e5\u7684\u7b80\u5355\u4f7f\u7528<br \/>\n<strong>\u5143\u7ec4\u7c7b\u578b\u7684\u6bd4\u8f83\u5224\u65ad<\/strong><br \/>\n\u5143\u7ec4\u4e4b\u95f4\u6bd4\u8f83\u6bcf\u4e2a\u6570\u636e\uff0c\u5982\u679c\u76f8\u540c\u5c31true\uff0c\u5982\u679c\u4e0d\u540c\u5c31false<\/p>\n<pre class=\"hl\"><code class=\"\">var a = (\"hello\",10)\nvar b = (\"hello\",10)\nif (a == b) {\n   print(\"a\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u8ddfb\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u76f8\u540c\")\n}else{\n   print(\"a\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u8ddfb\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u4e0d\u540c\")\n}\n\/*\n*\u7f16\u8bd1\u5668\u6253\u5370\u7ed3\u679c\uff1a\na\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u8ddfb\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u76f8\u540c\n*\/<\/code><\/pre>\n<pre class=\"hl\"><code class=\"\">var c = (true,233)\nvar d = (false,233)\nif (c == d) {\n   print(\"c\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u8ddfd\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u76f8\u540c\")\n}else{\n   print(\"c\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u8ddfd\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u4e0d\u540c\")\n}\n\/*\n*\u7f16\u8bd1\u5668\u6253\u5370\u7ed3\u679c\uff1a\nc\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u8ddfd\u5143\u7ec4\u4e2d\u7684\u6570\u636e\u4e0d\u540c\n*\/<\/code><\/pre>\n<pre class=\"hl\"><code class=\"\">var a = (3,2)\nvar b = (3,3)\nif (a &lt; b) {\n   print(\"a\u5c0f\u4e8eb\")\n}else{\n   print(\"a\u4e0d\u5c0f\u4e8eb\")\n}\n\/*\n*\u7f16\u8bd1\u5668\u6253\u5370\u7ed3\u679c\uff1a\na\u5c0f\u4e8eb\n*\/<\/code><\/pre>\n<p><strong>\u6bd4\u8f83\u5b57\u7b26\u4e32<\/strong><\/p>\n<pre class=\"hl\"><code class=\"\">var a = \"Hello\"\nvar b = \"hello\"\nif (a == b) {\n   print(\"a\u7b49\u4e8eb\")\n}else{\n   print(\"a\u4e0d\u7b49\u4e8eb\")\n}\n\/*\n*\u7f16\u8bd1\u5668\u6253\u5370\u7ed3\u679c\uff1a\na\u4e0d\u7b49\u4e8eb\n*\/<\/code><\/pre>\n<pre class=\"hl\"><code class=\"\">var a = \"a\"\nvar b = \"A\"\nif (a &lt; b) {\n   print(\"a\u5c0f\u4e8eb\")\n}else{\n   print(\"a\u4e0d\u5c0f\u4e8eb\")\n}\n\/*\n*\u7f16\u8bd1\u5668\u6253\u5370\u7ed3\u679c\uff1a\na\u4e0d\u5c0f\u4e8eb\n*\/<\/code><\/pre>\n<p><strong>\u5229\u7528if\u8bed\u53e5\u8fdb\u884c\u53ef\u9009\u7c7b\u578b\u7684\u53ef\u9009\u9879\u7ed1\u5b9a<\/strong><br \/>\n\u5982\u679c\u53ef\u9009\u7c7b\u578b\u91cc\u6709\u503c\uff0c\u90a3\u4e48\u53ef\u4ee5\u5229\u7528if let \u6216\u8005 if var \u8bed\u6cd5\u8fdb\u884c\u89e3\u6790\u503c\uff0c\u800c\u4e14\u4e0d\u7528\u52a0\u611f\u53f9\u53f7<\/p>\n<pre class=\"hl\"><code class=\"\">var a:String? = \"hello\"\n\/\/\u6ce8\u610f\u8fd9\u91cc\u7684\u53ef\u9009\u7c7b\u578bb\u6ca1\u6709\u52a0\u611f\u53f9\u53f7\u89e3\u6790\u503c\nif let valueA = a {\n\/\/\u5982\u679ca\u6709\u503c\u5c31\u6253\u5370valueA\n   print(valueA)\n}else{\n   print(\"a\u6ca1\u503c\")\n}\n\nvar b:String? = nil\n\/\/\u6ce8\u610f\u8fd9\u91cc\u7684\u53ef\u9009\u7c7b\u578bb\u6ca1\u6709\u52a0\u611f\u53f9\u53f7\u89e3\u6790\u503c\nif var valueB = b {\n\/\/\u5982\u679cb\u6709\u503c\u5c31\u6253\u5370valueB\n   print(valueB)\n}else{\n   print(\"b\u6ca1\u503c\")\n}\n\/*\n*\u7f16\u8bd1\u5668\u6253\u5370\u7ed3\u679c\uff1a\nhello\nb\u6ca1\u503c\n*\/<\/code><\/pre>\n<p><strong>\u9690\u5f0f\u5c55\u5f00<\/strong><br \/>\n\u5982\u679c\u660e\u786e\u4e86\u53ef\u9009\u7c7b\u578b\u6709\u503c\uff0c\u90a3\u4e48\u5c31\u4e0d\u7528\u6bcf\u6b21\u90fd\u662f\u7528<code class=\"\">!<\/code>\u6765\u89e3\u6790\u503c\uff0c\u5728\u5b9a\u4e49\u53d8\u91cf\u7684\u65f6\u5019\u76f4\u63a5\u7528<code class=\"\">!<\/code>\u6807\u8bb0\u5373\u53ef\u5982\u4e0b\u4ee3\u7801<\/p>\n<pre class=\"hl\"><code class=\"\">\/\/\u5df2\u7ecf\u660e\u786evalue\u6709\u503c\uff0c\u90a3\u4e48\u5b9a\u4e49\u65f6\u4e0d\u9700\u8981\u7528?\uff0c\u7528!\u5c31\u884c\uff0c\u8fd9\u6837\u4e0b\u9762\u518d\u4f7f\u7528value\u65f6\uff0c\u5c31\u4e0d\u7528!\u89e3\u6790\u503c\u4e86\nvar value:String! = \"hello world\"\n\/\/\u8fd9\u4e2avalue\u662f\u53ef\u9009\u7c7b\u578b\uff0c\u4f46\u662f\u5e76\u6ca1\u7528!\u89e3\u6790\u503c\nvar getValue:String = value\nprint(getValue)\n\/*\n*\u7f16\u8bd1\u5668\u6253\u5370\u7ed3\u679c\uff1a\nhello world\n*\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>swift\u4e2d\u7684if\u8bed\u53e5\u548c\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u7684if\u8bed\u53e5\uff0c\u5728\u7528\u6cd5\u548c\u5199\u6cd5\u4e0a\uff0c\u51e0\u4e4e\u5b8c\u5168\u4e00\u6837\u3002 \u53ea\u662fSwift\u4e2d\u7684if\u8bed\u53e5\u540e\u9762\u5c0f\u62ec\u53f7\u53ef\u4ee5\u4e0d\u7528\u5199\uff0c\u4f46 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":70,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[3],"tags":[8,10,12],"class_list":["post-49","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-3","tag-swift","tag-10","tag-12"],"_links":{"self":[{"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":1,"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":77,"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/posts\/49\/revisions\/77"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/media\/70"}],"wp:attachment":[{"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yomisoft.com\/index.php\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}