{"id":557,"date":"2023-02-25T19:02:24","date_gmt":"2023-02-25T11:02:24","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=557"},"modified":"2023-04-29T20:36:35","modified_gmt":"2023-04-29T12:36:35","slug":"swift-interval-operator","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/swift-interval-operator\/","title":{"rendered":"Swift &#8211; \u533a\u95f4\u8fd0\u7b97\u7b26"},"content":{"rendered":"<blockquote>\n<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4<\/p>\n<\/blockquote>\n<p>\u533a\u95f4\u8fd0\u7b97\u7b26\u53ef\u4ee5\u7528\u6765\u8868\u793a\u4e24\u4e2a\u64cd\u4f5c\u6570\u4e4b\u95f4\u7684\u8303\u56f4\u96c6\u5408\u3002<\/p>\n<p><!-- more --><\/p>\n<h3>\u95ed\u533a\u95f4\u8fd0\u7b97\u7b26\uff1aa&#8230;b<\/h3>\n<pre><code class=\"language-swift\">for iCount in 1...10 {\n    \/\/\u4ece1\u904d\u5386\u523010\uff08\u5305\u62ec10\uff09\n}<\/code><\/pre>\n<h3>\u534a\u95ed\u533a\u95f4\u8fd0\u7b97\u7b26\uff1aa..&lt;b<\/h3>\n<pre><code class=\"language-swift\">var fruts = [&quot;apple&quot;,&quot;orange&quot;,&quot;banana&quot;]\nlet iCount = fruts.count\nfor i in 0..&lt;iCount {\n    print(&quot;\u7b2c\\(i+1)\u4e2a\u6c34\u679c\u662f\\(fruts[i])&quot;)\n}<\/code><\/pre>\n<h3>\u5012\u5e8f\u5faa\u73af<\/h3>\n<p>\u901a\u8fc7 reversed() \u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4e00\u4e2a\u6b63\u5e8f\u5faa\u73af\u53d8\u6210\u9006\u5e8f\u5faa\u73af\u3002<\/p>\n<pre><code class=\"language-swift\">for i in (0..&lt;10).reversed() {\n    print(i)\n}<\/code><\/pre>\n<h3>\u5b57\u7b26\u4e32\u8303\u56f4\u4e5f\u53ef\u4ee5\u4f7f\u7528\u533a\u95f4\u8fd0\u7b97\u7b26<\/h3>\n<pre><code class=\"language-swift\">\/\/\u5b57\u7b26\u4e32\u622a\u53d6\nlet words = &quot;appblog.cn&quot;\n\n\/\/\u4e0d\u4f7f\u7528\u533a\u95f4\u8fd0\u7b97\u7b26\nlet index1 = words.index(words.startIndex, offsetBy: 4)\nlet index2 = words.index(words.startIndex, offsetBy: 6)\nlet range = Range(uncheckedBounds: (lower: index1, upper: index2))\nlet rangeStr = words.substring(with: range) \/\/lo\nprint(rangeStr)\n\n\/\/\u4f7f\u7528\u533a\u95f4\u8fd0\u7b97\u7b26\nlet range2 = words.index(words.startIndex, offsetBy: 4)..&lt;words.index(words.startIndex, offsetBy: 6)\nlet rangeStr2 = words.substring(with: range2) \/\/lo\nprint(rangeStr2)<\/code><\/pre>\n<h3>Comparable<\/h3>\n<p>\u533a\u95f4\u8fd0\u7b97\u7b26\u9664\u4e86\u8fd4\u56de\u4e00\u4e2aRange\u5916\uff0c\u8fd8\u53ef\u4ee5\u63a5\u53d7Comparable\u7684\u8f93\u5165\uff0c\u8fd4\u56deClosedInterval\u6216HalfOpenInterval<\/p>\n<p>\u53ef\u4ee5\u7528\u8fd9\u4e2a\u7279\u6027\u68c0\u67e5\u5b57\u7b26\u4e32\u91cc\u7684\u5b57\u7b26\u662f\u4e0d\u662f\u90fd\u662f\u5408\u6cd5\u5b57\u7b26\uff08\u6bd4\u5982\u662f\u4e0d\u662f\u90fd\u662f\u5c0f\u5199\uff09<\/p>\n<pre><code class=\"language-swift\">let words = &quot;AppBlog.CN&quot;\n\nlet interval = &quot;a&quot;...&quot;z&quot;\nfor c in words.characters {\n    if !interval.contains(String(c)) {\n        print(&quot;\\(c)\u4e0d\u662f\u5c0f\u5199\u5b57\u6bcd&quot;)\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4 \u533a\u95f4\u8fd0\u7b97\u7b26\u53ef\u4ee5\u7528\u6765\u8868\u793a\u4e24\u4e2a\u64cd\u4f5c\u6570\u4e4b\u95f4\u7684\u8303\u56f4\u96c6\u5408\u3002 \u95ed\u533a\u95f4\u8fd0\u7b97\u7b26\uff1aa&#8230; [&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-557","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/557","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=557"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/557\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}