Downcast<\/a> \u3092\u884c\u3046\u6a5f\u4f1a\u306f\u5c11\u306a\u304b\u3089\u305a\u3042\u308a\u307e\u3059. \u3053\u306e\u969b\u306b Downcast (\u30c0\u30a6\u30f3\u30ad\u30e3\u30b9\u30c8) (\u578b\u5909\u63db) \u3092\u884c\u3046\u65b9\u6cd5\u306b\u3088\u3063\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u5927\u304d\u306a\u5dee\u304c\u51fa\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059.<\/p>\n<\/p>\n
\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u5909\u5316\u3059\u308b\u6761\u4ef6\u306b\u3064\u3044\u3066<\/h2>\n
[[String: Int]] \u306e\u578b\u3067\u8868\u73fe\u3067\u304d\u308b AnyObject \u3092 Downcast \u3059\u308b\u5834\u5408, AnyObject? -> [[String: Int]] \u3068\u76f4\u63a5 Downcast \u3059\u308b\u306e\u3068, AnyObject? -> [AnyObject] \u3068 Downcast \u3057\u3066\u304b\u3089\u3055\u3089\u306b AnyObject -> [String: Int] \u306b Downcast \u3059\u308b\u306e\u3067\u306f\u5f8c\u8005\u306e\u65b9\u304c\u6570\u500d\u901f\u3044\u3068\u3044\u3046\u73fe\u8c61\u3067\u3059.<\/p>\n
\u30c6\u30b9\u30c8\u5185\u5bb9\u306b\u3064\u3044\u3066<\/h2>\n
\u3053\u3053\u3067\u306f JSON \u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067, \u305d\u306e\u7d50\u679c\u3092 Downcast \u3057\u3066 Swift \u3067\u5229\u7528\u3059\u308b\u3053\u3068\u3092\u8003\u3048\u307e\u3059. JSON \u306e\u8aad\u307f\u8fbc\u307f\u306b\u306f\u00a0NSJSONSerialization \u3092\u7528\u3044\u307e\u3059. \u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092 NSData \u306b\u8aad\u307f\u8fbc\u307f, \u305d\u306e NSData \u3092\u00a0NSJSONSerialization.JSONObjectWithData \u3067\u8aad\u307f\u8fbc\u307f\u307e\u3059. NSJSONSerialization.JSONObjectWithData \u306f AnyObject? \u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u307e\u3059.<\/p>\n
\u30c6\u30b9\u30c8\u306b\u5229\u7528\u3059\u308b\u306e\u306f\u4ee5\u4e0b\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u914d\u5217\u3092\u8868\u3059 JSON \u30d5\u30a1\u30a4\u30eb\u3067\u3059. \u305d\u308c\u305e\u308c\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f26\u500b\u306e\u8981\u7d20\u3092\u6301\u3061, \u3053\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c 1,000 \u500b\u5165\u3063\u305f\u914d\u5217\u306b\u306a\u3063\u3066\u3044\u307e\u3059. Swift \u306e\u578b\u3067\u8868\u73fe\u3059\u308b\u306a\u3089 [[String: Int]] \u3067\u3059. \u3053\u306e\u30b5\u30f3\u30d7\u30eb\u30d5\u30a1\u30a4\u30eb\u306f Python 3 \u3067\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059.<\/p>\n
\r\n[\r\n {"a": 1, "o": 15, "t": 20, "y": 25, "k": 11, "e": 5, "l": 12, "b": 2, "z": 26, "c": 3, "v": 22, "r": 18, "u": 21, "d": 4, "p": 16, "j": 10, "w": 23, "n": 14, "i": 9, "f": 6, "h": 8, "x": 24, "g": 7, "q": 17, "s": 19, "m": 13},\r\n {"a": 1, "o": 15, "t": 20, "y": 25, "k": 11, "e": 5, "l": 12, "b": 2, "z": 26, "c": 3, "v": 22, "r": 18, "u": 21, "d": 4, "p": 16, "j": 10, "w": 23, "n": 14, "i": 9, "f": 6, "h": 8, "x": 24, "g": 7, "q": 17, "s": 19, "m": 13},\r\n {"a": 1, "o": 15, "t": 20, "y": 25, "k": 11, "e": 5, "l": 12, "b": 2, "z": 26, "c": 3, "v": 22, "r": 18, "u": 21, "d": 4, "p": 16, "j": 10, "w": 23, "n": 14, "i": 9, "f": 6, "h": 8, "x": 24, "g": 7, "q": 17, "s": 19, "m": 13},\r\n\r\n \u301c\u301c\u301c \u4e2d\u7565 \u301c\u301c\u301c\r\n\r\n {"a": 1, "o": 15, "t": 20, "y": 25, "k": 11, "e": 5, "l": 12, "b": 2, "z": 26, "c": 3, "v": 22, "r": 18, "u": 21, "d": 4, "p": 16, "j": 10, "w": 23, "n": 14, "i": 9, "f": 6, "h": 8, "x": 24, "g": 7, "q": 17, "s": 19, "m": 13}\r\n]\r\n<\/pre>\n\u3053\u3053\u3067\u306f\u4e0a\u8a18\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u305d\u308c\u305e\u308c\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6570\u5024\u306e\u548c\u3092\u6c42\u3081\u307e\u3059. (\u3064\u307e\u308a 26 * 1,000 = 26,000 \u306e\u6570\u5024\u306e\u548c\u3092\u6c42\u3081\u308b)<\/p>\n
1\u3064\u76ee\u306e\u65b9\u6cd5\u306f NSJSONSerialization.JSONObjectWithData \u3067\u8fd4\u3055\u308c\u308b AnyObject? \u3092\u76f4\u63a5 [[String: Int]] \u306b Downcast \u3059\u308b\u65b9\u6cd5\u3067\u3059. \u548c\u306f Swift \u3089\u3057\u304f reduce \u3067\u6c42\u3081\u307e\u3059.<\/p>\n
\r\nlet list1 = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: &error) as [[String: Int]]\r\nsum = list1.reduce(0, combine: { $0 + reduce($1.values, 0, +) })\r\n<\/pre>\n2\u3064\u76ee\u306e\u65b9\u6cd5\u3067\u306f NSJSONSerialization.JSONObjectWithData \u3067\u8fd4\u3055\u308c\u308b AnyObject? \u3092\u4e00\u65e6 AnyObject \u306e\u914d\u5217 [AnyObject] \u306b Downcast \u3057\u3066, \u305d\u306e AnyObject \u3092\u5229\u7528\u3059\u308b\u969b\u306b\u518d\u5ea6 AnyObject -> [String: Int] \u306e Downcast \u3092\u3059\u308b\u65b9\u6cd5\u3067\u3059.<\/p>\n
\r\nlet list2 = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: &error) as [AnyObject]\r\nsum = list2.reduce(0, combine: { $0 + reduce(($1 as [String: Int]).values, 0, +) })\r\n<\/pre>\n\u3053\u308c\u3089\u306e\u30b3\u30fc\u30c9\u306f GitHub<\/a> \u3067\u516c\u958b\u3057\u3066\u3044\u307e\u3059.<\/p>\n\u30b3\u30f3\u30d1\u30a4\u30eb\u3068\u5b9f\u884c<\/h2>\n
\u4e0a\u8a18\u306e\u51e6\u7406\u3092 iOS \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u4e0a\u306e UIButton \u3092\u30bf\u30c3\u30d7\u3059\u308b\u3068\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u308b\u306e\u3067, \u305d\u308c\u3067\u5b9f\u884c\u3057\u307e\u3059. \u74b0\u5883\u306f OS X Yosemite (14A329f) \/ Xcode 6.0.1 (6A317) \/ iOS 8 (12A365) \u3067 iPhone 5s \u5b9f\u6a5f\u3068 iPhone 5s Simulator \u3067\u5b9f\u884c\u3057\u307e\u3059. \u6700\u9069\u5316\u30aa\u30d7\u30b7\u30e7\u30f3\u3082 Onone, O, Ounchecked \u306e3\u7a2e\u985e\u3067\u8a66\u3057\u307e\u3059.<\/p>\n
\u30c6\u30b9\u30c8\u7d50\u679c<\/h2>\n
\u30c6\u30b9\u30c8\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f. \u65b9\u6cd51\u306f\u76f4\u63a5 Downcast \u3059\u308b\u65b9\u6cd5 (AnyObject? -> [[String: Int]]), \u65b9\u6cd52\u306f2\u6bb5\u968e\u306b\u5206\u3051\u3066 Downcast \u3059\u308b\u65b9\u6cd5 (AnyObject? -> [AnyObject], AnyObject -> [String: Int]) \u3067\u3059.<\/p>\n
iPhone 5s Simulator<\/h3>\nOnone<\/h4>\n \r\n\u65b9\u6cd51: 1.5 [sec]\r\n\u65b9\u6cd52: 0.65 [sec]\r\n<\/pre>\nO<\/h4>\n \r\n\u65b9\u6cd51: 1.2 [sec]\r\n\u65b9\u6cd52: 0.32 [sec]\r\n<\/pre>\nOunchecked<\/h4>\n \r\n\u65b9\u6cd51: 1.2 [sec]\r\n\u65b9\u6cd52: 0.31 [sec]\r\n<\/pre>\niPhone 5s<\/h3>\nOnone<\/h4>\n \r\n\u65b9\u6cd51: 5.5 [sec]\r\n\u65b9\u6cd52: 2.2 [sec]\r\n<\/pre>\nO<\/h4>\n \r\n\u65b9\u6cd51: 4.4 [sec]\r\n\u65b9\u6cd52: 1.1 [sec]\r\n<\/pre>\nOunchecked<\/h4>\n \r\n\u65b9\u6cd51: 4.2 [sec]\r\n\u65b9\u6cd52: 1.0 [sec]\r\n<\/pre>\n\u307e\u3068\u3081<\/h2>\n
Simulator (x64) \u3068 iPhone 5s (arm64) \u3067\u540c\u3058\u50be\u5411\u304c\u51fa\u3066\u3044\u307e\u3059. \u65b9\u6cd52\u306e\u65b9\u304c\u65b9\u6cd51\u306b\u6bd4\u3079\u3066\u901f\u3044\u7d50\u679c\u306b\u306a\u308a\u307e\u3057\u305f. \u6700\u9069\u5316\u306a\u3057\u306e\u5834\u5408\u306f\u65b9\u6cd52\u304c2\u500d\u7a0b\u5ea6\u901f\u304f, \u6700\u9069\u5316\u3042\u308a\u306e\u5834\u5408\u306f\u65b9\u6cd52\u304c4\u500d\u7a0b\u5ea6\u901f\u3044\u7d50\u679c\u306b\u306a\u308a\u307e\u3059.<\/p>\n
AnyObject \u304b\u3089\u306e Downcast \u306f\u3057\u3070\u3057\u3070\u5229\u7528\u3055\u308c\u308b\u305f\u3081, \u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u91cd\u8981\u306a\u90e8\u5206\u3084\u30b5\u30a4\u30ba\u306e\u5927\u304d\u3044 AnyObject \u3092 Downcast \u3059\u308b\u5834\u5408\u306f\u6ce8\u610f\u3057\u3066\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u306e\u304c\u826f\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093.<\/p>\n
\u8ffd\u8a18: Xcode 6.1 \/ iOS 8.1 \u3067\u306e\u30c6\u30b9\u30c8<\/h2>\n
Xcode 6.1 \u3068 iOS 8.1 \u304c\u6b63\u5f0f\u30ea\u30ea\u30fc\u30b9\u3068\u306a\u3063\u305f\u305f\u3081, \u6539\u3081\u3066\u30c6\u30b9\u30c8\u3092\u884c\u3044\u307e\u3057\u305f. \u74b0\u5883\u306f OS X Yosemite (14A388a) \/ Xcode 6.1 (6A1052d) \/ iOS 8.1 (12B411) \u3067 iPhone 5s \u5b9f\u6a5f\u3068 iPhone 5s Simulator \u3067\u5b9f\u884c\u3057\u307e\u3059. \u6700\u9069\u5316\u30aa\u30d7\u30b7\u30e7\u30f3\u3082 Onone, O, Ounchecked \u306e3\u7a2e\u985e\u3067\u8a66\u3057\u307e\u3059.<\/p>\n
iPhone 5s Simulator<\/h3>\nOnone<\/h4>\n \r\n\u65b9\u6cd51: 1.92 [sec]\r\n\u65b9\u6cd52: 0.78 [sec]\r\n<\/pre>\nO<\/h4>\n \r\n\u65b9\u6cd51: 1.51 [sec]\r\n\u65b9\u6cd52: 0.37 [sec]\r\n<\/pre>\nOunchecked<\/h4>\n \r\n\u65b9\u6cd51: 1.40 [sec]\r\n\u65b9\u6cd52: 0.35 [sec]\r\n<\/pre>\niPhone 5s<\/h3>\nOnone<\/h4>\n \r\n\u65b9\u6cd51: 6.16 [sec]\r\n\u65b9\u6cd52: 2.33 [sec]\r\n<\/pre>\nO<\/h4>\n \r\n\u65b9\u6cd51: 4.97 [sec]\r\n\u65b9\u6cd52: 1.14 [sec]\r\n<\/pre>\nOunchecked<\/h4>\n \r\n\u65b9\u6cd51: 4.93 [sec]\r\n\u65b9\u6cd52: 1.13 [sec]\r\n<\/pre>\n\u8ffd\u8a18: Xcode 6.1 \/ iOS 8.1 \u307e\u3068\u3081<\/h2>\n
\u65b9\u6cd52\u306e\u65b9\u304c\u65b9\u6cd51\u3088\u308a\u901f\u3044\u50be\u5411\u306f, Xcode 6 \/ iOS 8 \u304b\u3089\u7279\u306b\u5909\u308f\u3063\u3066\u3044\u307e\u305b\u3093. Xcode 6 \/ iOS 8 \u306e\u6642\u306b\u6bd4\u3079\u3066, Xcode 6.1 \/ iOS 8.1 \u306e\u65b9\u304c\u3053\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3067\u306f\u5c11\u3057\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u4f4e\u4e0b\u3057\u3066\u3044\u308b\u3088\u3046\u306b\u3082\u898b\u3048\u307e\u3059.<\/p>\n","protected":false},"excerpt":{"rendered":"
JSON \u3092\u8aad\u307f\u8fbc\u3080\u5834\u5408\u3084, Objective-C \u306e\u30b3\u30fc\u30c9\u304b\u3089\u30c7\u30fc\u30bf\u3092\u6e21\u3059\u6642\u306a\u3069, Swift \u3067 Downcast \u3092\u884c\u3046\u6a5f\u4f1a\u306f\u5c11\u306a\u304b\u3089\u305a\u3042\u308a\u307e\u3059. \u3053\u306e\u969b\u306b Downcast (\u30c0\u30a6\u30f3\u30ad\u30e3\u30b9\u30c8) (\u578b\u5909\u63db) \u3092\u884c […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[11,60],"_links":{"self":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/531"}],"collection":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":17,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"predecessor-version":[{"id":679,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/531\/revisions\/679"}],"wp:attachment":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}