{"id":2987,"date":"2017-04-30T14:59:00","date_gmt":"2017-04-30T05:59:00","guid":{"rendered":"http:\/\/redwing.moo.jp\/cocoa\/?p=2987"},"modified":"2017-04-30T14:59:00","modified_gmt":"2017-04-30T05:59:00","slug":"swift3-0-%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%8f%be-%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"https:\/\/redwing.moo.jp\/cocoa\/archives\/2987","title":{"rendered":"Swift3.0 \u6b63\u898f\u8868\u73fe \u306b\u3064\u3044\u3066"},"content":{"rendered":"<p>\u904e\u53bb\u306e Swift \u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u8a18\u8ff0\u3057\u305f\u30b3\u30fc\u30c9\u304c Swift3.0 \u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u969b\u306b\u8b66\u544a\u3092\u51fa\u529b\u3057\u3066\u3044\u305f\u306e\u3067\u66f8\u304d\u76f4\u3057\u305f\uff0e<\/p>\n<p>\u7c21\u5358\u306b\u500b\u4eba\u7684\u306a\u30e1\u30e2<br \/>\n&#8211; Swift \u306f\u6b63\u898f\u8868\u73fe\u306f\uff0cNSRange \u306a\u3069\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u5c11\u3057\u9762\u5012\uff0e<br \/>\n&#8211; \u6b63\u898f\u8868\u73fe\u3092\u6271\u3046\u306b\u306f\uff0cNSRegularExpression \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f7f\u7528\u3059\u308b\uff0e<br \/>\n&#8211; \u6b63\u898f\u8868\u73fe\u306e\u691c\u7d22\u7d50\u679c\u3092\u53c2\u7167\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\uff0cregex.matches \u3092\u53c2\u7167\u3059\u308b\uff0e<br \/>\n&#8211; String \u30af\u30e9\u30b9\u306e characters.count \u306f\u6587\u5b57\u5217\u306e\u6587\u5b57\u3092\uff0c\u5168\u89d2\u534a\u89d2\u95a2\u4fc2\u306a\u304f\uff11\u6587\u5b57\u3068\u6570\u3048\u308b\uff0e<br \/>\n&#8211; NSString \u30af\u30e9\u30b9\u306e length \u306f\uff0c\u5168\u89d2\u6587\u5b57\u3092\u534a\u89d2\u6587\u5b572\u6587\u5b57\u5206\u3068\u3057\u3066\u6570\u3048\u308b\uff0e<\/p>\n<pre lang=\"objc\" line=\"1\">\r\nimport Foundation\r\nextension String {\r\n    var count: Int {\r\n        let string_NS = self as NSString\r\n        return string_NS.length\r\n    }\r\n    \r\n    \/\/ \u6b63\u898f\u8868\u73fe\u3067\u691c\u7d22\u3059\u308b\uff0e\r\n    \/\/ .caseInsensitive \u5927\u6587\u5b57\u5c0f\u6587\u5b57\u306e\u533a\u5225\u3092\u7121\u8996\u3059\u308b\r\n    func pregMatche(pattern: String, options: NSRegularExpression.Options = [.caseInsensitive]) -> Bool {\r\n        guard let regex = try? NSRegularExpression(pattern: pattern, options: options) else {\r\n            return false\r\n        }\r\n        let matches = regex.matches(in: self, options: [], range: NSMakeRange(0, self.count))\r\n        return matches.count > 0\r\n    }\r\n    \r\n    \/\/ \u6b63\u898f\u8868\u73fe\u3067\u691c\u7d22\u3059\u308b\uff0e(\u691c\u7d22\u7d50\u679c\u3092\u4f7f\u7528)\r\n    func pregMatche(pattern: String, options: NSRegularExpression.Options = [.caseInsensitive], matches: inout [String]) -> Bool {\r\n        guard let regex = try? NSRegularExpression(pattern: pattern, options: options) else {\r\n            return false\r\n        }\r\n        let targetStringRange = NSRange(location: 0, length: self.count)\r\n        let results = regex.matches(in: self, options: [], range: targetStringRange)\r\n        for i in 0 ..< results.count {\r\n            for j in 0 ..< results[i].numberOfRanges {\r\n                let range = results[i].rangeAt(j)\r\n                matches.append((self as NSString).substring(with: range))\r\n            }\r\n        }\r\n        return results.count > 0\r\n    }\r\n}\r\n<\/pre>\n<a href=\"https:\/\/twitter.com\/redwing1300?ref_src=twsrc%5Etfw\" class=\"twitter-follow-button\" data-size=\"large\" data-show-count=\"false\">Follow @redwing1300<\/a><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content --><div id=\"redwi-885786445\" class=\"redwi- redwi-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9652476346722993\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:block;\" data-ad-client=\"ca-pub-9652476346722993\" \ndata-ad-slot=\"\" \ndata-ad-format=\"auto\"><\/ins>\n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>\u904e\u53bb\u306e Swift \u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u8a18\u8ff0\u3057\u305f\u30b3\u30fc\u30c9\u304c Swift3.0 \u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u969b\u306b\u8b66\u544a\u3092\u51fa\u529b\u3057\u3066\u3044\u305f\u306e\u3067\u66f8\u304d\u76f4\u3057\u305f\uff0e \u7c21\u5358\u306b\u500b\u4eba\u7684\u306a\u30e1\u30e2 &#8211; Swift \u306f\u6b63\u898f\u8868\u73fe\u306f\uff0cNSRange \u306a\u3069\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981 &hellip; <a href=\"https:\/\/redwing.moo.jp\/cocoa\/archives\/2987\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,116],"tags":[],"class_list":["post-2987","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift"],"_links":{"self":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/2987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/comments?post=2987"}],"version-history":[{"count":6,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/2987\/revisions"}],"predecessor-version":[{"id":2993,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/2987\/revisions\/2993"}],"wp:attachment":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/media?parent=2987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/categories?post=2987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/tags?post=2987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}