{"id":538,"date":"2024-10-04T21:54:28","date_gmt":"2024-10-04T21:54:28","guid":{"rendered":"https:\/\/wp.shimayugu.jp\/?p=538"},"modified":"2024-10-04T21:54:28","modified_gmt":"2024-10-04T21:54:28","slug":"%e6%96%b0swift%e3%81%a7%e8%a1%8c%e3%81%93%e3%81%86%e7%ac%ac%ef%bc%95%ef%bc%97%e5%9b%9e%e3%80%8c%e3%83%8f%e3%82%a4%e3%82%a2%e3%83%b3%e3%83%89%e3%83%ad%e3%83%bc%e3%82%b2%e3%83%bc%e3%83%a0","status":"publish","type":"post","link":"https:\/\/wp.shimayugu.jp\/?p=538","title":{"rendered":"\u65b0Swift\u3067\u884c\u3053\u3046\u2026\u7b2c\uff15\uff17\u56de\u300c\u30cf\u30a4\u30a2\u30f3\u30c9\u30ed\u30fc\u30b2\u30fc\u30e0\uff16\u89e3\u8aac\u300d\u3000\u7530\u90e8\u4e95\u4fdd"},"content":{"rendered":"\n<p><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2298\">\u76ee\u6b21<\/a>\u3000<a href=\"https:\/\/wp.shimayugu.jp\/?p=84\">\u901a\u5e38\u7248<\/a><\/p>\n\n\n\n<p>\u3000\u30cf\u30a4\u30a2\u30f3\u30c9\u30ed\u30fc\u30b2\u30fc\u30e0\uff16\u306e\u89e3\u8aac\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u307e\u305a\u524d\u534a\u90e8\u5206\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"8,9-12,14,18\" data-show-lang=\"1\"><code>    \/\/\/\u30dc\u30bf\u30f3\u62bc\u4e0b\u6642\u51e6\u7406\n    @IBAction func TouchBtnGo(_ sender: Any) {\n        \/\/\u56de\u6570\u52a0\u7b97\n        cnt = cnt + 1\n        \/\/\u56de\u6570\u8868\u793a\n        Count.text = cnt.description + &quot;\u56de\u76ee&quot;\n        \/\/\u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5165\u308c\u305f\u5024\u3092\u6570\u5024\u3068\u3057\u3066val\u5909\u6570\u306b\u5165\u308c\u308b\n        let val = Int(Input.text!)\n        \/\/\u5165\u529b\u6b04\u304c\u7a7a\u767d\u3001\u3042\u308b\u3044\u306f\u6570\u5024\u4ee5\u5916\n        if val == nil {\n            Guide.text = &quot;\u6570\u5024\u3092\u5165\u308c\u3066\u4e0b\u3055\u3044&quot;\n        }\n        \/\/\u5165\u529b\u5024\u3068\u4e71\u6570\u3092\u6bd4\u3079\u3066\u5165\u529b\u5024\u304c\u5927\u304d\u3044\u5834\u5408\n        else if val! &gt; randInt {\n            Guide.text = &quot;\u3082\u3063\u3068\u5c0f\u3055\u3044\u3067\u3059&quot;\n        }\n        \/\/\u5165\u529b\u5024\u3068\u4e71\u6570\u3092\u6bd4\u3079\u3066\u5165\u529b\u5024\u304c\u5c0f\u3055\u3044\u5834\u5408\n        else if val! &lt; randInt {\n            Guide.text = &quot;\u3082\u3063\u3068\u5927\u304d\u3044\u3067\u3059&quot;\n        }\n        \/\/\u4e0a\u8a18\u4ee5\u5916\u3001\u7b49\u3057\u3044\u6642\n        else {\n            Guide.text = &quot;\u5f53\u305f\u308a\u3067\u3059&quot;\n            \/\/OK\u30dc\u30bf\u30f3\u306e\u8868\u793a\u3068\u62bc\u4e0b\u6642\u51e6\u7406\u8a18\u8ff0\n            \/\/\u62bc\u4e0b\u6642reset\u95a2\u6570\u3092\u547c\u3076\n            let okAction = UIAlertAction(title: &quot;OK&quot;, style: .default)\n            { (action) in\n                self.reset()\n            }\n            \/\/\u30a2\u30e9\u30fc\u30c8\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5b9a\u7fa9\n            \/\/\u30bf\u30a4\u30c8\u30eb\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u307e\u3068\u3081\u305f\n            \/\/\u30b9\u30bf\u30a4\u30eb\u306f\u30a2\u30e9\u30fc\u30c8\n            let alert = UIAlertController(title: &quot;\u5f53\u305f\u308a&quot;, message: &quot;\u5f53\u305f\u308a\u3067\u3059&quot;, preferredStyle: .alert)\n            \/\/\u30a2\u30e9\u30fc\u30c8\u30a2\u30af\u30b7\u30e7\u30f3\n            alert.addAction(okAction)\n            \/\/\u30a2\u30e9\u30fc\u30c8\u3092\u51fa\u3059\n            present(alert, animated: true, completion: nil)\n        }\n    }<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\uff18\u884c\u76ee\u306e\u3000Input.text!\u3000\u3067\u3059\u304c\u3001Input.text\u3000\u3060\u3068String?\u578b\u3068\u306a\u308a\u307e\u3059\u3002String\u578b\u306f\u6587\u5b57\u5217\u578b\u3001String?\u578b\u306f\u6587\u5b57\u5217\u3068\u7a7a\u767d\u3092\u8868\u3059nil\u304c\u5165\u308b\u4e8b\u306e\u51fa\u6765\u308b\u578b\u3068\u306a\u308a\u307e\u3059\u3002String?\u578b\u306e\u3082\u306e\u306b ! \u3092\u4ed8\u3051\u308b\u3068\u7121\u7406\u3084\u308aString\u578b\u306b\u3059\u308b\u4e8b\u304c\u51fa\u6765\u307e\u3059\u3002Int( )\u306e\u62ec\u5f27\u306e\u4e2d\u306f\u3053\u306e\u5834\u5408\u306fString\u578b\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u8a66\u3057\u306b ! \u3092\u53d6\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p> Int(Input.text!)\u3000\u3067\u3059\u304c\u3001\u3053\u308c\u306fInt?\u578b\u3068\u306a\u308a\u307e\u3059\u3002\u6574\u6570\u3068nil\u3092\u53d6\u308b\u4e8b\u304c\u51fa\u6765\u307e\u3059\u3002\u3053\u3053\u3092\u4ee5\u524d\u306f\u3000Int(Input.text!)! \u3068\u6700\u5f8c\u306b\u3082 ! \u3092\u4ed8\u3051\u3066\u7121\u7406\u3084\u308aInt\u578b\u306b\u3057\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3092\u3059\u308b\u3068\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u4f55\u3082\u5165\u308c\u306a\u304b\u3063\u305f\u6642\u3001\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u7b49\u6570\u5024\u4ee5\u5916\u3092\u5165\u308c\u305f\u6642\u306b\u5b9f\u884c\u6642\u30a8\u30e9\u30fc\u3068\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u5b9f\u884c\u6642\u30a8\u30e9\u30fc\u3092\u907f\u3051\u308b\u305f\u3081\u3001\u6700\u5f8c\u306e ! \u306f\u53d6\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u305d\u3057\u3066\u3001\u307e\u305a val \u3068 nil \u3092\u6bd4\u3079\u3066 nil \u3060\u3063\u305f\u3089\u6570\u5024\u3092\u5165\u308c\u308b\u3088\u3046\u306b\u4fc3\u3057\u307e\u3059\u3002\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u4f55\u3082\u5165\u308c\u306a\u3044\u3001\u3042\u308b\u3044\u306f\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u7b49\u6570\u5024\u4ee5\u5916\u3092\u5165\u308c\u305f\u5834\u5408\u3001val \u306b\u306f nil \u304c\u5165\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u3053\u3053\u3067 else \u3068\u306a\u3063\u305f\u5834\u5408\u3001val \u306b\u306f\u6570\u5024\u304c\u5165\u3063\u3066\u3044\u308b\u4e8b\u304c\u4fdd\u8a3c\u3055\u308c\u308b\u306e\u3067\u3001val \u306b ! \u3092\u4ed8\u3051\u3066Int?\u578b\u3092Int\u578b\u306b\u3057\u3066\u6bd4\u8f03\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u308c\u304c\uff11\uff14\u884c\u76ee\u3001\uff11\uff18\u884c\u76ee\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u7d9a\u3044\u3066\u5f8c\u534a\u90e8\u5206\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"9-40\" data-show-lang=\"1\"><code>    \/\/\/\u30dc\u30bf\u30f3\u62bc\u4e0b\u6642\u51e6\u7406\n    @IBAction func TouchBtnGo(_ sender: Any) {\n        \/\/\u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5165\u308c\u305f\u5024\u3092\u6570\u5024\u3068\u3057\u3066val\u5909\u6570\u306b\u5165\u308c\u308b\n        let val = Int(Input.text!)\n        \/\/\u5165\u529b\u6b04\u304c\u7a7a\u767d\u3001\u3042\u308b\u3044\u306f\u6570\u5024\u4ee5\u5916\n        if val == nil {\n            Guide.text = &quot;\u6570\u5024\u3092\u5165\u308c\u3066\u4e0b\u3055\u3044&quot;\n        }\n        else {\n            \/\/\u56de\u6570\u52a0\u7b97\n            cnt = cnt + 1\n            \/\/\u56de\u6570\u8868\u793a\n            Count.text = cnt.description + &quot;\u56de\u76ee&quot;\n            \/\/\u5165\u529b\u5024\u3068\u4e71\u6570\u3092\u6bd4\u3079\u3066\u5165\u529b\u5024\u304c\u5927\u304d\u3044\u5834\u5408\n            if val! &gt; randInt {\n                Guide.text = &quot;\u3082\u3063\u3068\u5c0f\u3055\u3044\u3067\u3059&quot;\n            }\n            \/\/\u5165\u529b\u5024\u3068\u4e71\u6570\u3092\u6bd4\u3079\u3066\u5165\u529b\u5024\u304c\u5c0f\u3055\u3044\u5834\u5408\n            else if val! &lt; randInt {\n                Guide.text = &quot;\u3082\u3063\u3068\u5927\u304d\u3044\u3067\u3059&quot;\n            }\n            \/\/\u4e0a\u8a18\u4ee5\u5916\u3001\u7b49\u3057\u3044\u6642\n            else {\n                Guide.text = &quot;\u5f53\u305f\u308a\u3067\u3059&quot;\n                \/\/OK\u30dc\u30bf\u30f3\u306e\u8868\u793a\u3068\u62bc\u4e0b\u6642\u51e6\u7406\u8a18\u8ff0\n                \/\/\u62bc\u4e0b\u6642reset\u95a2\u6570\u3092\u547c\u3076\n                let okAction = UIAlertAction(title: &quot;OK&quot;, style: .default)\n                { (action) in\n                    self.reset()\n                }\n                \/\/\u30a2\u30e9\u30fc\u30c8\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5b9a\u7fa9\n                \/\/\u30bf\u30a4\u30c8\u30eb\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u307e\u3068\u3081\u305f\n                \/\/\u30b9\u30bf\u30a4\u30eb\u306f\u30a2\u30e9\u30fc\u30c8\n                let alert = UIAlertController(title: &quot;\u5f53\u305f\u308a&quot;, message: &quot;\u5f53\u305f\u308a\u3067\u3059&quot;, preferredStyle: .alert)\n                \/\/\u30a2\u30e9\u30fc\u30c8\u30a2\u30af\u30b7\u30e7\u30f3\n                alert.addAction(okAction)\n                \/\/\u30a2\u30e9\u30fc\u30c8\u3092\u51fa\u3059\n                present(alert, animated: true, completion: nil)\n            }\n        }\n    }<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u56de\u6570\u52a0\u7b97\u3068\u56de\u6570\u8868\u793a\u3092\u3001\u3053\u306e\u95a2\u6570\u306e\u6700\u521d\u3067\u3084\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u307e\u305a\u5165\u529b\u5024\u3092\u6570\u5024\u306b\u5909\u63db\u3057\u3066\u307f\u3066\u3001\u6570\u5024\u306b\u3067\u304d\u306a\u304b\u3063\u305f\u6642\u306f\u300c\u6570\u5024\u3092\u5165\u308c\u3066\u4e0b\u3055\u3044\u300d\u3068\u8868\u793a\u3057\u3001\u305d\u308c\u4ee5\u5916\u306a\u3089\u3001\u56de\u6570\u52a0\u7b97\u3068\u56de\u6570\u8868\u793a\u3092\u884c\u3044\u3001\u4e71\u6570\u3068\u5165\u529b\u5024\u3092\u6bd4\u3079\u3066\u3001\u305d\u308c\u306b\u3088\u3063\u3066\u3001\u300c\u3082\u3063\u3068\u5927\u304d\u3044\u3067\u3059\u300d\u3001\u300c\u3082\u3063\u3068\u5c0f\u3055\u3044\u3067\u3059\u300d\u3084\u5f53\u305f\u308a\u306e\u6642\u306e\u8868\u793a\u3068\u521d\u671f\u5316\u3092\u884c\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2298\">\u76ee\u6b21<\/a>\u3000<a href=\"https:\/\/wp.shimayugu.jp\/?p=84\">\u901a\u5e38\u7248<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21\u3000\u901a\u5e38\u7248 \u3000\u30cf\u30a4\u30a2\u30f3\u30c9\u30ed\u30fc\u30b2\u30fc\u30e0\uff16\u306e\u89e3\u8aac\u3067\u3059\u3002 \u3000\u307e\u305a\u524d\u534a\u90e8\u5206\u3067\u3059\u3002 \u3000\uff18\u884c\u76ee\u306e\u3000Input.text!\u3000\u3067\u3059\u304c\u3001Input.text\u3000\u3060\u3068String?\u578b\u3068\u306a\u308a\u307e\u3059\u3002String\u578b\u306f\u6587\u5b57\u5217\u578b\u3001String?\u578b\u306f\u6587\u5b57 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-538","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=538"}],"version-history":[{"count":8,"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions\/671"}],"wp:attachment":[{"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}