{"id":47,"date":"2024-09-13T11:21:55","date_gmt":"2024-09-13T11:21:55","guid":{"rendered":"https:\/\/xcode15.shimayugu.jp\/?p=47"},"modified":"2024-12-29T06:29:20","modified_gmt":"2024-12-28T21:29:20","slug":"%e6%96%b0swift%e3%81%a7%e8%a1%8c%e3%81%93%e3%81%86-%e7%ac%ac%ef%bc%96%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%ef%bc%93%e3%80%8d","status":"publish","type":"post","link":"https:\/\/xcode15.shimayugu.jp\/?p=47","title":{"rendered":"\u65b0Swift\u3067\u884c\u3053\u3046&#8230;\u7b2c\uff16\u56de\u300c\u30cf\u30a4\u30a2\u30f3\u30c9\u30ed\u30fc\u30b2\u30fc\u30e0\uff13\u300d\u3000\u7530\u90e8\u4e95\u4fdd"},"content":{"rendered":"\n<p><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2298\"><\/a><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2473\">\u76ee\u6b21<\/a>\u3000<a href=\"https:\/\/xcode15.shimayugu.jp\/?p=496\">\u89e3\u8aac\u7de8<\/a><\/p>\n\n\n\n<p>\u3000\u3055\u3066\u3001\u4eca\u5ea6\u306f<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-show-lang=\"1\"><code>            randInt = Int.random(in: 0 ..&lt; 10)\n            cnt = 0\n            Guide.text = &quot;0~9\u306e\u6570\u5b57\u3092\u5165\u308c\u3066\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u4e0b\u3055\u3044&quot;\n<\/code><\/pre><\/div>\n\n\n\n<p>\u306e\u90e8\u5206\u304c\u6700\u521d\u3068\u3001\u5f53\u305f\u3063\u3066\u304b\u3089\u306e\u51e6\u7406\u306e2\u7b87\u6240\u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"16,23,26-31,49\" data-show-lang=\"1\"><code>\/\/\n\/\/  ViewController.swift\n\/\/  Hi and Lo\n\/\/\n\/\/  Created by \u4fdd Tabei on 2024\/08\/30.\n\/\/\n\nimport UIKit\n\nclass ViewController: UIViewController {\n\n    @IBOutlet weak var Guide: UILabel!\n    @IBOutlet weak var Input: UITextField!\n    @IBOutlet weak var Count: UILabel!\n    \n    var randInt = 0\n    var cnt = 0\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ Do any additional setup after loading the view.\n        Count.text = &quot;0\u56de\u76ee&quot;\n        reset()\n    }\n    \n    func reset()\n    {\n        randInt = Int.random(in: 0 ..&lt; 10)\n        cnt = 0\n        Guide.text = &quot;0~9\u306e\u6570\u5b57\u3092\u5165\u308c\u3066\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u4e0b\u3055\u3044&quot;\n    }\n\n    @IBAction func TouchBtnGo(_ sender: Any) {\n        cnt = cnt + 1\n        Count.text = cnt.description + &quot;\u56de\u76ee&quot;\n        let val = Int(Input.text!)!\n        if val &gt; randInt {\n            Guide.text = &quot;\u3082\u3063\u3068\u5c0f\u3055\u3044\u3067\u3059&quot;\n        } \n        else if val &lt; randInt {\n            Guide.text = &quot;\u3082\u3063\u3068\u5927\u304d\u3044\u3067\u3059&quot;\n        } \n        else {\n            let alert = UIAlertController()\n            alert.title = &quot;\u5f53\u305f\u308a&quot;\n            alert.message = &quot;\u5f53\u305f\u308a\u3067\u3059&quot;\n            alert.addAction(UIAlertAction(title: &quot;OK&quot;, style: .default, handler: nil))\n            present(alert, animated: true, completion: nil)\n            reset()\n        }\n    }\n    \n}<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u3053\u308c\u3067\u7d50\u69cb\u3059\u3063\u304d\u308a\u3057\u307e\u3057\u305f\u306d\u3002<\/p>\n\n\n\n<p>\u3000\u4eca\u5ea6\u306f\u3001\u521d\u7d1a(0~9)\u3001\u4e2d\u7d1a(0~19)\u3068\u9078\u629e\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u30bb\u30b0\u30e1\u30f3\u30c6\u30c3\u30c9\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"1024\" src=\"https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-6-647x1024.png\" alt=\"\" class=\"wp-image-49\" srcset=\"https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-6-647x1024.png 647w, https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-6-189x300.png 189w, https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-6.png 768w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/figure>\n\n\n\n<p>\u3000\u753b\u9762\u4e0a\u306e\u9069\u5f53\u306a\u4f4d\u7f6e\u306b\u914d\u7f6e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"622\" src=\"https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-7-1024x622.png\" alt=\"\" class=\"wp-image-50\" srcset=\"https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-7-1024x622.png 1024w, https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-7-300x182.png 300w, https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-7-768x467.png 768w, https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-7-1536x934.png 1536w, https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-7-2048x1245.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u3000\u4e00\u756a\u4e0a\u306b\u914d\u7f6e\u3057\u3066\u898b\u307e\u3057\u305f\u3002\u914d\u7f6e\u3057\u305f\u30bb\u30b0\u30e1\u30f3\u30c6\u30c3\u30c9\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u9078\u629e\u3057\u3066\u3001\u4e00\u756a\u53f3\u306e\u67a0\u306e\u4e0a\u90e8\u306e\u30a2\u30a4\u30b3\u30f3\u3001\u5de6\u304b\u3089\uff15\u756a\u76ee\u3092\u9078\u3073\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"536\" height=\"657\" src=\"https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-8.png\" alt=\"\" class=\"wp-image-51\" srcset=\"https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-8.png 536w, https:\/\/xcode15.shimayugu.jp\/wp-content\/uploads\/2024\/08\/image-8-245x300.png 245w\" sizes=\"auto, (max-width: 536px) 100vw, 536px\" \/><\/figure>\n\n\n\n<p>\u3000Segment\u304c\u300cSegment 0 &#8211; First\u300d\u3068\u306a\u3063\u3066\u3044\u308b\u306e\u3092\u78ba\u8a8d\u3057\u3066\u3001\u305d\u306e\u4e0b\u306eTitle\u306b\u300c\u521d\u7d1a\u300d\u3068\u5165\u308c\u3066\u30a8\u30f3\u30bf\u30fc\u30ad\u30fc\u3092\u62bc\u3057\u307e\u3059\u3002\u7d9a\u3044\u3066\u3001Segment\u3092\u300cSegment 1 &#8211; Second\u300d\u3068\u3057\u3066\u3001Title\u306b\u300c\u4e2d\u7d1a\u300d\u3068\u5165\u308c\u3066\u30a8\u30f3\u30bf\u30fc\u30ad\u30fc\u3092\u62bc\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u30bb\u30b0\u30e1\u30f3\u30c6\u30c3\u30c9\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u9078\u629e\u3057\u3066\u3001control\u30ad\u30fc\u3092\u62bc\u3057\u306a\u304c\u3089\u30c9\u30e9\u30c3\u30b0\u3057\u3066\u30b3\u30fc\u30c9\u9818\u57df\u306b\u30c9\u30ed\u30c3\u30d7 \u3057\u307e\u3059\u3002\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u304c\u51fa\u308b\u306e\u3067\u3001Name\u6b04\u306b\u300cLevel\u300d\u3068\u5165\u529b\u3057\u3066\u3001\u300cConnect\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000reset\u95a2\u6570\u306e\u4e2d\u8eab\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-show-lang=\"1\"><code>    func reset()\n    {\n        if Level.selectedSegmentIndex == 0 {\n            randInt = Int.random(in: 0 ..&lt; 10)\n            Guide.text = &quot;0~9\u306e\u6570\u5b57\u3092\u5165\u308c\u3066\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u4e0b\u3055\u3044&quot;\n        } else {\n            randInt = Int.random(in: 0 ..&lt; 20)\n            Guide.text = &quot;0~19\u306e\u6570\u5b57\u3092\u5165\u308c\u3066\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u4e0b\u3055\u3044&quot;\n        }\n        cnt = 0\n    }\n<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u53f3\u4e0a\u306e\u4e00\u756a\u53f3\u306e\u30a2\u30a4\u30b3\u30f3\u3092\u9078\u3073\u3001Value Changed\u306e\u53f3\u5074\u306e\u25cb\u304b\u3089\u30c9\u30e9\u30c3\u30b0\u3057\u3066\u3001\u30b3\u30fc\u30c9\u4e0a\u306e\u9069\u5207\u306a\u4f4d\u7f6e \u306b\u30c9\u30ed\u30c3\u30d7\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u304c\u51fa\u308b\u306e\u3067\u3001Name\u6b04\u306b\u300cLevelChange\u300d\u3068\u5165\u529b\u3057\u3066\u3001\u300cConnect\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u307e\u3059\u3002 \u633f\u5165\u3055\u308c\u305f\u95a2\u6570\u306e\u672c\u6587\u306b<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-show-lang=\"1\"><code>    @IBAction func LevelChange(_ sender: Any)\n    {\n        reset()\n    }\n<\/code><\/pre><\/div>\n\n\n\n<p>\u3068\u66f8\u304d\u307e\u3059\u3002 \u4ee5\u4e0b\u5168\u4f53\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\" data-line=\"15,29-36,39-42\" data-show-lang=\"1\"><code>\/\/\n\/\/  ViewController.swift\n\/\/  Hi and Lo\n\/\/\n\/\/  Created by \u4fdd Tabei on 2024\/08\/30.\n\/\/\n\nimport UIKit\n\nclass ViewController: UIViewController {\n\n    @IBOutlet weak var Guide: UILabel!\n    @IBOutlet weak var Input: UITextField!\n    @IBOutlet weak var Count: UILabel!\n    @IBOutlet weak var Level: UISegmentedControl!\n    \n    var randInt:Int = 0\n    var cnt:Int = 0\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ Do any additional setup after loading the view.\n        Count.text = &quot;0\u56de\u76ee&quot;\n        reset()\n    }\n    \n    func reset()\n    {\n        if Level.selectedSegmentIndex == 0 {\n            randInt = Int.random(in: 0 ..&lt; 10)\n            Guide.text = &quot;0~9\u306e\u6570\u5b57\u3092\u5165\u308c\u3066\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u4e0b\u3055\u3044&quot;\n        } else {\n            randInt = Int.random(in: 0 ..&lt; 20)\n            Guide.text = &quot;0~19\u306e\u6570\u5b57\u3092\u5165\u308c\u3066\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u3066\u4e0b\u3055\u3044&quot;\n        }\n        cnt = 0\n    }\n\n    @IBAction func LevelChange(_ sender: Any)\n    {\n        reset()\n    }\n    \n    @IBAction func TouchBtnGo(_ sender: Any) {\n        cnt = cnt + 1\n        Count.text = cnt.description + &quot;\u56de\u76ee&quot;\n        let val = Int(Input.text!)!\n        if val &gt; randInt {\n            Guide.text = &quot;\u3082\u3063\u3068\u5c0f\u3055\u3044\u3067\u3059&quot;\n        } \n        else if val &lt; randInt {\n            Guide.text = &quot;\u3082\u3063\u3068\u5927\u304d\u3044\u3067\u3059&quot;\n        } \n        else {\n            let alert = UIAlertController()\n            alert.title = &quot;\u5f53\u305f\u308a&quot;\n            alert.message = &quot;\u5f53\u305f\u308a\u3067\u3059&quot;\n            alert.addAction(UIAlertAction(title: &quot;OK&quot;, style: .default, handler: nil))\n            present(alert, animated: true, completion: nil)\n            reset()\n        }\n    }\n    \n}<\/code><\/pre><\/div>\n\n\n\n<p><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2298\"><\/a><a href=\"https:\/\/shimayugu.sakura.ne.jp\/?p=2473\">\u76ee\u6b21<\/a>\u3000<a href=\"https:\/\/xcode15.shimayugu.jp\/?p=496\">\u89e3\u8aac\u7de8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21\u3000\u89e3\u8aac\u7de8 \u3000\u3055\u3066\u3001\u4eca\u5ea6\u306f \u306e\u90e8\u5206\u304c\u6700\u521d\u3068\u3001\u5f53\u305f\u3063\u3066\u304b\u3089\u306e\u51e6\u7406\u306e2\u7b87\u6240\u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3059\u3002 \u3000\u3053\u308c\u3067\u7d50\u69cb\u3059\u3063\u304d\u308a\u3057\u307e\u3057\u305f\u306d\u3002 \u3000\u4eca\u5ea6\u306f\u3001\u521d\u7d1a(0~9)\u3001\u4e2d\u7d1a(0~19)\u3068\u9078\u629e\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u30bb\u30b0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lightning_design_setting":{"layout":"default"},"footnotes":""},"categories":[4],"tags":[],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=47"}],"version-history":[{"count":13,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":995,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=\/wp\/v2\/posts\/47\/revisions\/995"}],"wp:attachment":[{"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xcode15.shimayugu.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}