{"id":522,"date":"2018-02-23T23:38:58","date_gmt":"2018-02-23T15:38:58","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/swift-for-in-%e5%be%aa%e7%8e%af\/"},"modified":"2018-02-23T23:38:58","modified_gmt":"2018-02-23T15:38:58","slug":"swift-for-in-%e5%be%aa%e7%8e%af","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=522","title":{"rendered":"Swift for-in \u5faa\u73af"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>Swift for-in \u5faa\u73af<\/h1>\n<p><a href=\"\/swift-loops.html\"><img decoding=\"async\" class=\"navup\" src=\"\/images\/up.gif\" alt=\"Swift \u5faa\u73af\">Swift \u5faa\u73af<\/a><\/p>\n<p>Swift for-in \u5faa\u73af\u7528\u4e8e\u904d\u5386\u4e00\u4e2a\u96c6\u5408\u91cc\u9762\u7684\u6240\u6709\u5143\u7d20\uff0c\u4f8b\u5982\u7531\u6570\u5b57\u8868\u793a\u7684\u533a\u95f4\u3001\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3001\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u3002<\/p>\n<h3>\u8bed\u6cd5<\/h3>\n<p>Swift for-in \u5faa\u73af\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>\nfor index in var {\n   \u5faa\u73af\u4f53\n}\n<\/pre>\n<p><b>\u6d41\u7a0b\u56fe\uff1a<\/b><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2015\/11\/forin_loop.jpg\"><\/p>\n<h3>\u5b9e\u4f8b 1<\/h3>\n<pre>\nimport Cocoa\n\nfor index in 1...5 {\n    print(\"\\(index) \u4e58\u4e8e 5 \u4e3a\uff1a\\(index * 5)\")\n}\n<\/pre>\n<p>\u4f8b\u5b50\u4e2d\u7528\u6765\u8fdb\u884c\u904d\u5386\u7684\u5143\u7d20\u662f\u4f7f\u7528\u95ed\u533a\u95f4\u64cd\u4f5c\u7b26\uff08&#8230;\uff09\u8868\u793a\u7684\u4ece1\u52305\u7684\u6570\u5b57\u533a\u95f4\u3002i<\/p>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n1 \u4e58\u4e8e 5 \u4e3a\uff1a5\n2 \u4e58\u4e8e 5 \u4e3a\uff1a10\n3 \u4e58\u4e8e 5 \u4e3a\uff1a15\n4 \u4e58\u4e8e 5 \u4e3a\uff1a20\n5 \u4e58\u4e8e 5 \u4e3a\uff1a25\n<\/pre>\n<h3>\u5b9e\u4f8b 2<\/h3>\n<pre>\nimport Cocoa\n\nvar someInts:[Int] = [10, 20, 30]\n\nfor index in someInts {\n   print( \"index \u7684\u503c\u4e3a \\(index)\")\n}\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\nindex \u7684\u503c\u4e3a 10\nindex \u7684\u503c\u4e3a 20\nindex \u7684\u503c\u4e3a 30\n<\/pre>\n<p><a href=\"\/swift-loops.html\"><img decoding=\"async\" class=\"navup\" src=\"\/images\/up.gif\" alt=\"Swift \u5faa\u73af\">Swift \u5faa\u73af<\/a><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">Swift for-in \u5faa\u73af Swift \u5faa\u73af Swift for-in \u5faa\u73af\u7528\u4e8e\u904d\u5386\u4e00&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=522\">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-522","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\/522","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=522"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/522\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}