{"id":483,"date":"2015-07-15T14:40:42","date_gmt":"2015-07-15T05:40:42","guid":{"rendered":"http:\/\/www.nukoneko.info\/blog\/?p=483"},"modified":"2016-04-22T16:33:59","modified_gmt":"2016-04-22T07:33:59","slug":"swift%e3%81%a7%e9%85%8d%e5%88%97%e3%81%8b%e3%82%89%e5%80%a4%e3%82%92%e5%8f%96%e3%82%8a%e5%87%ba%e3%81%9d%e3%81%86%e3%81%a8%e3%81%97%e3%81%9f%e6%99%82%e3%81%ab%e3%82%a8%e3%83%a9%e3%83%bc%e5%90%90","status":"publish","type":"post","link":"https:\/\/www.nukoneko.info\/blog\/?p=483","title":{"rendered":"Swift\u3067\u914d\u5217\u304b\u3089\u5024\u3092\u53d6\u308a\u51fa\u305d\u3046\u3068\u3057\u305f\u6642\u306b\u30a8\u30e9\u30fc\u5410\u3044\u305f"},"content":{"rendered":"<p>Cannot subscript a value of type &#8216;[AnyObject]?&#8217; with an index of type &#8216;Int&#8217;<br \/>\n<!--more--><\/p>\n<p>\u30a8\u30e9\u30fc\u6587\u304c\u308f\u304b\u308a\u3065\u3089\u3044&#8230;<\/p>\n<p>Cannot  &#8220;subscript&#8221; a value of type<br \/>\nsubscript \u3068\u306f\u3001\u914d\u5217\u3078\u306e\u8981\u7d20\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u969b\u306e [&#8220;hoge&#8221;] \u307f\u305f\u3044\u306a\u3082\u306e<\/p>\n<pre class=\"brush: swift; title: ; notranslate\" title=\"\">\r\n\/\/'&#x5B;AnyObject]?' with an index of type 'Int' \u306e\u5834\u5408\u306f\r\nvar arr : &#x5B;AnyObject]?\r\n\/\/ \u3068\u306a\u3063\u3066\u3044\u308b\u6642\u306b\u51fa\u308b\u3002 \u914d\u5217\u304cOptional\u3060\u304b\u3089\u306a\u306e\u3067\u78ba\u5b9a\u3057\u3066\u304b\u3089 dict!&#x5B;0] \u306e\u3088\u3046\u306b\u53d6\u308a\u51fa\u305b\u308b\r\nlet dat = arr!&#x5B;0]\r\n\/\/ \u5b89\u5168\u306b\u53d6\u308a\u51fa\u3059\u306a\u3089 guard \u3092\u4f7f\u3063\u305f\u308a...\r\nguard let dat = arr?&#x5B;0] else {\r\n  return\r\n}\r\n\r\n\/\/ \u8f9e\u66f8\u578b\u306f\u3001\r\nlet dict : &#x5B;String : String] = &#x5B;&quot;Yamamoto&quot; : &quot;\u7537\u6027&quot;] \r\n\/\/ \u306b\u3001 dict&#x5B;0] \u3067\u53d6\u308a\u51fa\u3059\u3068 Cannot subscript a value of type \u3092\u51fa\u3059\u304c\r\n\/\/ \u3053\u3061\u3089\u306fKey\u304cString\u306e\u305f\u3081 (&quot;Yamamoto&quot; \u306e\u65b9\r\nlet gend = dict&#x5B;&quot;Yamamoto&quot;]  \/\/\u306a\u3089\u3044\u3051\u308b\r\n<\/pre>\n<hr>\n<p><strong> \u3053\u306e\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u5f53\u6642\u306f\u3001tabbar\u306e viewControllers \u306f AnyObject \u3060\u3063\u305f&#8230; \u3060\u304b\u3089\u4e0b\u306e\u306f(\u8a00\u3063\u3066\u308b\u3053\u3068\u3082)\u9055\u3044\u307e\u3059\u304c\u3001\u6b8b\u3057\u3066\u3042\u308a\u307e\u3059<\/strong><\/p>\n<p>\u3084\u308d\u3046\u3068\u3057\u305f\u3053\u3068\u306f\u3001TabBar\u306eviewControllers\u3092\u6bd4\u8f03\u3057\u3088\u3046\u3068\u3057\u305f\u6642<\/p>\n<pre class=\"brush: swift; title: ; notranslate\" title=\"\">\r\nfunc tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -&gt; Bool {\r\n\/\/ Cannot subscript a value of type '&#x5B;AnyObject]?' with an index of type 'Int'\r\nvar vc : UIViewController = self.viewControllers&#x5B;1] as! UIViewController;\r\n\/\/~~\r\n}\r\n<\/pre>\n<p>&#8220;Cannot subscript a value of type &#8216;[AnyObject]?&#8217; with an index of type &#8216;Int'&#8221;<\/p>\n<p>\u3042\u3068&#8230;  viewControllers\u81ea\u4f53\u304cOptional\u306a\u306e\u3067 ! \u3092\u3064\u3051\u308b<\/p>\n<p>\u6b63\u89e3<\/p>\n<pre class=\"brush: swift; title: ; notranslate\" title=\"\">\r\nfunc tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -&gt; Bool {\r\n\/\/var vc : UIViewController = self.viewControllers&#x5B;1] as! UIViewController;\r\nvar vc : UIViewController = self.viewControllers!&#x5B;1] as! UIViewController;\r\n\/\/~~\r\n}\r\n<\/pre>\n<p>\u5b89\u5168\u306e\u305f\u3081\u306b<\/p>\n<pre class=\"brush: swift; title: ; notranslate\" title=\"\">\r\nif let vc = self.viewControllers?&#x5B;1] as? UIViewController {\r\n\r\n}\r\n<\/pre>\n<p>\u3068\u304b\u66f8\u3044\u305f\u307b\u3046\u304c\u3044\u3044\u304b\u3082..<\/p>\n<p>\u3067\u306f\u3067\u306f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cannot subscript a value of type &#8216;[AnyObject]?&#8217; with an index of type &#8216;Int&#8217;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-483","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=483"}],"version-history":[{"count":4,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions"}],"predecessor-version":[{"id":525,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions\/525"}],"wp:attachment":[{"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nukoneko.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}