{"id":330,"date":"2017-08-28T17:06:10","date_gmt":"2017-08-28T08:06:10","guid":{"rendered":"http:\/\/daily-memorials.net\/?p=330"},"modified":"2017-09-11T21:31:54","modified_gmt":"2017-09-11T12:31:54","slug":"swift%e5%ad%a6%e7%bf%92%e8%a8%98%e9%8c%b21","status":"publish","type":"post","link":"http:\/\/daily-memorials.net\/?p=330","title":{"rendered":"swift\u5b66\u7fd2\u8a18\u9332(1)"},"content":{"rendered":"<p>swift\u3068objective-c(C\u8a00\u8a9e)\u306e\u9055\u3044\u3092\u8e0f\u307e\u3048\u306a\u304c\u3089\u3001\u8a18\u6cd5\u306b\u3064\u3044\u3066\u5b66\u3093\u3067\u3044\u304f\u305f\u3081\u306e\u5099\u5fd8\u9332\u3067\u3059\u3002<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u30c7\u30fc\u30bf\u8868\u73fe<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">2<\/span> \u914d\u5217\u3068\u8f9e\u66f8<\/a><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_1\">3<\/span> \u95a2\u6570<\/a><\/li><li><a href=\"#i-4\"><span class=\"toc_number toc_depth_1\">4<\/span> \u30aa\u30d7\u30b7\u30e7\u30ca\u30eb<\/a><ul><li><a href=\"#i-5\"><span class=\"toc_number toc_depth_2\">4.1<\/span> \u30a2\u30f3\u30e9\u30c3\u30d7<\/a><\/li><\/ul><\/li><\/ul><\/div>\n<h2><span id=\"i\">\u30c7\u30fc\u30bf\u8868\u73fe<\/span><\/h2>\n<p>\u307e\u305a\u6570\u5b57\u306e\u8868\u73fe\u304b\u3089\u3067\u3059\u3002C\u8a00\u8a9e\u3067\u306f\u5b9a\u6570\u306fconst\u3092\u3064\u3051\u3066\u8868\u3057\u3066\u3044\u307e\u3057\u305f\u3002swift\u3067\u306f\u5909\u6570\u306b\u306fvar,\u5b9a\u6570\u306b\u306flet\u3092\u3064\u3051\u3066\u8868\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvar test1 = 10 \/\/var\u306f\u5b9a\u6570\r\nlet test2 = 40 \/\/let\u306f\u5b9a\u6570\r\n<\/pre>\n<p>\u3053\u306e\u8868\u73fe\u306f\u6570\u5b57\u306b\u9650\u3089\u305a\u3001\u6587\u5b57\u5217\u306b\u95a2\u3057\u3066\u3082\u540c\u3058\u3067\u3059\u3002Objective-C\u3067\u306fNSString\u3092\u4f7f\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3060\u3044\u3076\u7c21\u7565\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvar test1 = &quot;hello&quot;\r\n<\/pre>\n<p>\u6587\u5b57\u5217\u306b\u5909\u6570\u306e\u6570\u5b57\u3092\u7d50\u5408\u3059\u308b\u3053\u3068\u3082\u7c21\u5358\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/objective-c\r\nint num1 = 3;\r\nNSString *str = [NSString stringWithFormat:@&quot;I have %d apples&quot;,num1);\r\n\/\/swift\r\nlet num1 = 3\r\nlet str = &quot;I have \\(num1) apples&quot; \/\/\u6587\u5b57\u5217\u306e\u9023\u7d50\r\nprint(str)\r\n<\/pre>\n<h2><span id=\"i-2\">\u914d\u5217\u3068\u8f9e\u66f8<\/span><\/h2>\n<p>\u914d\u5217\u3084\u8f9e\u66f8\u306b\u3082var\u3084let\u3092\u7528\u3044\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/objective-c\r\nNSArray *array = [@&quot;a&quot;,@&quot;b&quot;,@&quot;c&quot;,@&quot;d&quot;] \/\/\u914d\u5217\r\nNSDictionary *occupations = [@&quot;Haru&quot;:@&quot;Spring&quot;, \/\/\u8f9e\u66f8\r\n                    @&quot;Natsu&quot;:@&quot;Summer&quot;,]\r\n\/\/swift\r\nlet array = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] \/\/\u914d\u5217\r\nvar occupations = [&quot;Haru&quot;:&quot;Spring&quot;, \/\/\u8f9e\u66f8\r\n                    &quot;Natsu&quot;:&quot;Summer&quot;,]\r\n<\/pre>\n<h2><span id=\"i-3\">\u95a2\u6570<\/span><\/h2>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nfunc greet(person: String, day: String) -&gt; String {\r\n    return &quot;Hello \\(person), today is \\(day).&quot;\r\n}\r\n<\/pre>\n<h2><span id=\"i-4\">\u30aa\u30d7\u30b7\u30e7\u30ca\u30eb<\/span><\/h2>\n<p>\u4e00\u822c\u306b\u306f\u5909\u6570\u306bnil\u3092\u4ee3\u5165\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002?\u3084!\u3092\u3064\u3051\u308b\u3068\u30aa\u30d7\u30b7\u30e7\u30ca\u30eb\u578b\u3068\u306a\u3063\u3066nil\u3092\u8a31\u5bb9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/optional\u306b\u3064\u3044\u3066\r\nvar optionalString :String? = nil \/\/\u30a8\u30e9\u30fc\u304c\u51fa\u308b\r\nvar optionalString :String? = &quot;Hello&quot;\r\nvar optionalString :String? = nil \/\/\u30a8\u30e9\u30fc\u304c\u51fa\u306a\u3044\r\n<\/pre>\n<h3><span id=\"i-5\">\u30a2\u30f3\u30e9\u30c3\u30d7<\/span><\/h3>\n<p>\u30aa\u30d7\u30b7\u30e7\u30ca\u30eb\u5909\u6570\u3092\u7528\u3044\u308b\u6642\u306b\u306f\u30a2\u30f3\u30e9\u30c3\u30d7\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002?\u3067\u5ba3\u8a00\u3057\u305f\u3082\u306e\u306f\u5909\u6570\u306e\u5f8c\u306b!\u3092\u3064\u3051\u308b\u3053\u3068\u3067\u5f37\u5236\u30a2\u30f3\u30e9\u30c3\u30d7\u304c\u3001?\u3092\u4ed8\u3051\u308b\u3053\u3068\u3067Optional Chaining(nil\u304c\u5165\u3063\u305f\u51e6\u7406\u306f\u30b9\u30ad\u30c3\u30d7)\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001Optional Binding(if\u6587\u306e\u7d44\u307f\u5408\u308f\u305b\u3066\u5909\u6570\u306enil\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3046)\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059<br \/>\n!\u3067\u5ba3\u8a00\u3057\u305f\u3082\u306e\u306f\u4fee\u98fe\u3057\u306a\u304f\u3066\u3082\u81ea\u52d5\u7684\u306b\u5f37\u5236\u30a2\u30f3\u30e9\u30c3\u30d7\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvar optionalString :String? = nil\r\nprint(optionalString.lowercased()) \/\/\u5f37\u5236\u30a2\u30f3\u30e9\u30c3\u30d7(\u30a8\u30e9\u30fc\u304c\u51fa\u308b)\r\n\r\nvar optionalString :String? = &quot;test&quot; \r\nprint((optionalString?.lowercased())!) \/\/Optional Chaining(nil\u304c\u5165\u3063\u3066\u3044\u308b\u6642\u306e\u30e1\u30bd\u30c3\u30c9\u547c\u3073\u51fa\u3057\u5f8c\u306e\u5e30\u308a\u5024\u306fnil\u306b\u306a\u308b\u3002\u3053\u306e\u5834\u5408\u306f\u305d\u306e\u5f8c\u306b\u5f37\u5236\u30a2\u30f3\u30e9\u30c3\u30d7\u3057\u3066\u3044\u308b\u306e\u3067\u30a8\u30e9\u30fc\u3068\u306a\u308b\r\n\r\nlet string: String? = &quot;hello world&quot;\r\n\r\nif let bindString = string {    \/\/ Optional Binding\r\n    bindString = bindString.uppercaseString\r\n}\r\n\r\nlet a : Int? = nil\r\nlet b = a ?? 0 \/\/ b\u306b\u306f0\u304c\u4ee3\u5165\u3055\u308c\u308b \/\/nil coalescing operator\r\n\r\nvar optionalString :String! = nil\r\nprint(optionalString.lowercased()) \/\/(\u30a8\u30e9\u30fc\u304c\u51fa\u308b)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>swift\u3068objective-c(C\u8a00\u8a9e)\u306e\u9055\u3044\u3092\u8e0f\u307e\u3048\u306a\u304c\u3089\u3001\u8a18\u6cd5\u306b\u3064\u3044\u3066\u5b66\u3093\u3067\u3044\u304f\u305f\u3081\u306e\u5099\u5fd8\u9332\u3067\u3059\u3002 Contents1 \u30c7\u30fc\u30bf\u8868\u73fe2 \u914d\u5217\u3068\u8f9e\u66f83 \u95a2\u65704 \u30aa\u30d7\u30b7\u30e7\u30ca\u30eb4.1 \u30a2\u30f3\u30e9\u30c3\u30d7 \u30c7\u30fc\u30bf\u8868\u73fe \u307e\u305a\u6570\u5b57\u306e\u8868 &hellip; <a href=\"http:\/\/daily-memorials.net\/?p=330\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;swift\u5b66\u7fd2\u8a18\u9332(1)&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"http:\/\/daily-memorials.net\/index.php?rest_route=\/wp\/v2\/posts\/330"}],"collection":[{"href":"http:\/\/daily-memorials.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/daily-memorials.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/daily-memorials.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/daily-memorials.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=330"}],"version-history":[{"count":10,"href":"http:\/\/daily-memorials.net\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions"}],"predecessor-version":[{"id":437,"href":"http:\/\/daily-memorials.net\/index.php?rest_route=\/wp\/v2\/posts\/330\/revisions\/437"}],"wp:attachment":[{"href":"http:\/\/daily-memorials.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/daily-memorials.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/daily-memorials.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}