{"id":515,"date":"2018-02-23T23:38:56","date_gmt":"2018-02-23T15:38:56","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/swift-%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/"},"modified":"2018-02-23T23:38:56","modified_gmt":"2018-02-23T15:38:56","slug":"swift-%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=515","title":{"rendered":"Swift \u6761\u4ef6\u8bed\u53e5"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>Swift \u6761\u4ef6\u8bed\u53e5<\/h1>\n<p>\u6761\u4ef6\u8bed\u53e5\u901a\u8fc7\u8bbe\u5b9a\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u6761\u4ef6\u6765\u6267\u884c\u7a0b\u5e8f\uff0c\u5728\u6761\u4ef6\u4e3a\u771f\u65f6\u6267\u884c\u6307\u5b9a\u7684\u8bed\u53e5\uff0c\u5728\u6761\u4ef6\u4e3a false \u65f6\u6267\u884c\u53e6\u5916\u6307\u5b9a\u7684\u8bed\u53e5\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4e0b\u56fe\u6765\u7b80\u5355\u4e86\u89e3\u6761\u4ef6\u8bed\u53e5\u7684\u6267\u884c\u8fc7\u7a0b:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2015\/12\/if.png\"><\/p>\n<p>Swift \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u51e0\u79cd\u7c7b\u578b\u7684\u6761\u4ef6\u8bed\u53e5\uff1a<\/p>\n<table class=\"reference\">\n<tbody>\n<tr>\n<th style=\"width:35%;\">\u8bed\u53e5<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<tr>\n<td>\n<p><a href=\"\/swift\/if-statement.html\">if \u8bed\u53e5<\/a><\/p>\n<\/td>\n<td><b>if \u8bed\u53e5<\/b> \u7531\u4e00\u4e2a\u5e03\u5c14\u8868\u8fbe\u5f0f\u548c\u4e00\u4e2a\u6216\u591a\u4e2a\u6267\u884c\u8bed\u53e5\u7ec4\u6210\u3002<\/td>\n<\/tr>\n<tr>\n<td>\n<p><a href=\"\/swift\/if-else-statement.html\">if&#8230;else \u8bed\u53e5<\/a><\/p>\n<\/td>\n<td><b>if \u8bed\u53e5<\/b> \u540e\u53ef\u4ee5\u6709\u53ef\u9009\u7684 <b>else \u8bed\u53e5<\/b>,  <b>else \u8bed\u53e5<\/b>\u5728\u5e03\u5c14\u8868\u8fbe\u5f0f\u4e3a false \u65f6\u6267\u884c\u3002<\/td>\n<\/tr>\n<tr>\n<td>\n<p><a href=\"\/swift\/if-else-if-else-statement.html\">if&#8230;else if&#8230;else \u8bed\u53e5<\/a><\/p>\n<\/td>\n<td><b>if<\/b> \u540e\u53ef\u4ee5\u6709\u53ef\u9009\u7684 <b>else if&#8230;else<\/b> \u8bed\u53e5, <b>else if&#8230;else<\/b> \u8bed\u53e5\u5e38\u7528\u4e8e\u591a\u4e2a\u6761\u4ef6\u5224\u65ad\u3002<\/td>\n<\/tr>\n<tr>\n<td>\n<p><a href=\"\/swift\/nested-if-statement.html\">\u5185\u5d4c if \u8bed\u53e5<\/a><\/p>\n<\/td>\n<td>\u4f60\u53ef\u4ee5\u5728 <b>if<\/b> \u6216 <b>else if<\/b> \u4e2d\u5185\u5d4c <b>if<\/b> \u6216 <b>else if<\/b> \u8bed\u53e5\u3002<\/td>\n<\/tr>\n<tr>\n<td>\n<p><a href=\"\/swift\/switch-statement.html\">switch \u8bed\u53e5<\/a><\/p>\n<\/td>\n<td>switch \u8bed\u53e5\u5141\u8bb8\u6d4b\u8bd5\u4e00\u4e2a\u53d8\u91cf\u7b49\u4e8e\u591a\u4e2a\u503c\u65f6\u7684\u60c5\u51b5\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2>? : \u8fd0\u7b97\u7b26<\/h2>\n<p>\u6211\u4eec\u5df2\u7ecf\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d\u8bb2\u89e3\u4e86 <b>\u6761\u4ef6\u8fd0\u7b97\u7b26 ? :<\/b>\uff0c\u53ef\u4ee5\u7528\u6765\u66ff\u4ee3 <b>if&#8230;else<\/b> \u8bed\u53e5\u3002\u5b83\u7684\u4e00\u822c\u5f62\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>\nExp1 ? Exp2 : Exp3;\n<\/pre>\n<p>\u5176\u4e2d\uff0cExp1\u3001Exp2 \u548c Exp3 \u662f\u8868\u8fbe\u5f0f\u3002\u8bf7\u6ce8\u610f\uff0c\u5192\u53f7\u7684\u4f7f\u7528\u548c\u4f4d\u7f6e\u3002<\/p>\n<p>? \u8868\u8fbe\u5f0f\u7684\u503c\u662f\u7531 Exp1 \u51b3\u5b9a\u7684\u3002\u5982\u679c Exp1 \u4e3a\u771f\uff0c\u5219\u8ba1\u7b97 Exp2 \u7684\u503c\uff0c\u7ed3\u679c\u5373\u4e3a\u6574\u4e2a ? \u8868\u8fbe\u5f0f\u7684\u503c\u3002\u5982\u679c Exp1 \u4e3a\u5047\uff0c\u5219\u8ba1\u7b97 Exp3 \u7684\u503c\uff0c\u7ed3\u679c\u5373\u4e3a\u6574\u4e2a ? \u8868\u8fbe\u5f0f\u7684\u503c\u3002<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">Swift \u6761\u4ef6\u8bed\u53e5 \u6761\u4ef6\u8bed\u53e5\u901a\u8fc7\u8bbe\u5b9a\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u6761\u4ef6\u6765\u6267\u884c\u7a0b\u5e8f\uff0c\u5728\u6761\u4ef6\u4e3a\u771f\u65f6\u6267\u884c\u6307\u5b9a\u7684\u8bed&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=515\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,28],"tags":[74,119],"class_list":["post-515","post","type-post","status-publish","format-standard","hentry","category-mobile","category-swift","tag-ios","tag-swift","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=515"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/515\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}