{"id":609,"date":"2014-11-18T17:45:51","date_gmt":"2014-11-18T08:45:51","guid":{"rendered":"https:\/\/blog.ymyzk.com\/?p=609"},"modified":"2014-11-18T17:45:51","modified_gmt":"2014-11-18T08:45:51","slug":"swift-uint-int","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2014\/11\/swift-uint-int\/","title":{"rendered":"Swift \u3067\u306f\u57fa\u672c\u7684\u306b UInt \u3088\u308a Int \u3092\u7528\u3044\u308b\u3088\u3046\u306b\u3059\u308b"},"content":{"rendered":"

Swift \u3067\u306f\u975e\u8ca0\u6574\u6570\u3067\u3042\u308b\u3053\u3068\u304c\u81ea\u660e\u306a\u5834\u5408\u3067\u3082, \u7279\u5225\u306a\u7406\u7531\u304c\u306a\u3044\u5834\u5408 UInt \u3088\u308a Int \u3092\u7528\u3044\u308b\u306e\u304c\u826f\u3044\u3088\u3046\u3067\u3059.<\/p>\n

<\/p>\n

Int\/UInt \u306f\u305d\u308c\u305e\u308c Objective-C \u306e NSInteger\/NSUInteger \u306b\u76f8\u5f53\u3057, 32bit \u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3067\u306f 32bit, 64bit \u30d7\u30e9\u30c3\u30c8\u30c3\u30d5\u30a9\u30fc\u30e0\u3067\u306f 64bit \u306e\u7b26\u53f7\u4ed8\u304d\/\u7b26\u53f7\u306a\u3057\u6574\u6570\u3067\u3059.<\/p>\n

The Swift Programming Language \u306e Language Guide<\/a> \u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u8a18\u8ff0\u304c\u3042\u308a\u307e\u3059.<\/p>\n

Use UInt only when you specifically need an unsigned integer type with the same size as the platform\u2019s native word size. If this is not the case, Int is preferred, even when the values to be stored are known to be non-negative. A consistent use of Int for integer values aids code interoperability, avoids the need to convert between different number types, and matches integer type inference, as described in Type Safety and Type Inference.<\/p><\/blockquote>\n

\u3053\u308c\u306b\u3088\u308b\u3068\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u306e\u30ef\u30fc\u30c9\u30b5\u30a4\u30ba\u3068\u540c\u3058\u5927\u304d\u3055\u306e\u7b26\u53f7\u306a\u3057\u6574\u6570\u578b\u304c\u5fc5\u8981\u306a\u6642\u306e\u307f UInt \u3092\u4f7f\u3046\u3079\u304d<\/strong>\u3067, \u305f\u3068\u3048\u683c\u7d0d\u3055\u308c\u308b\u5024\u304c\u975e\u8ca0\u3067\u3042\u308b\u3053\u3068\u304c\u81ea\u660e\u306a\u5834\u5408\u3067\u3082 Int \u3092\u4f7f\u3046\u3088\u3046\u306b\u3057\u305f\u307b\u3046\u304c\u597d\u307e\u3057\u3044<\/strong>\u3068\u306e\u3053\u3068\u3067\u3059.<\/p>\n

Int \u3092\u4f7f\u3046\u3079\u304d\u7406\u7531\u3068\u3057\u3066\u306f, \u30b3\u30fc\u30c9\u306e\u76f8\u4e92\u904b\u7528\u6027\u3092\u52a9\u3051, \u7570\u306a\u308b\u6570\u5024\u578b\u306e\u9593\u3092\u5909\u63db\u3059\u308b\u5fc5\u8981\u3092\u907f\u3051\u308b\u3053\u3068\u306a\u3069\u304c\u6319\u3052\u3089\u308c\u3066\u3044\u307e\u3059.<\/p>\n

Swift \u3067\u306f Objective-C \u3068\u306f\u7570\u306a\u308a, Int <-> UInt \u306e\u9593\u3067\u306e\u578b\u5909\u63db\u306f\u660e\u793a\u7684\u306b\u8a18\u8ff0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081, Apple \u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3042\u308b\u3088\u3046\u306b\u901a\u5e38\u306f Int \u3092\u7528\u3044\u308b\u3088\u3046\u306b\u3057\u305f\u307b\u3046\u304c\u4e0d\u8981\u306a\u578b\u5909\u63db\u3092\u66f8\u304b\u305a\u306b\u6e08\u3080\u305f\u3081\u826f\u3055\u305d\u3046\u3067\u3059.<\/p>\n","protected":false},"excerpt":{"rendered":"

Swift \u3067\u306f\u975e\u8ca0\u6574\u6570\u3067\u3042\u308b\u3053\u3068\u304c\u81ea\u660e\u306a\u5834\u5408\u3067\u3082, \u7279\u5225\u306a\u7406\u7531\u304c\u306a\u3044\u5834\u5408 UInt \u3088\u308a Int \u3092\u7528\u3044\u308b\u306e\u304c\u826f\u3044\u3088\u3046\u3067\u3059.<\/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":[60],"_links":{"self":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/609"}],"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=609"}],"version-history":[{"count":4,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/609\/revisions"}],"predecessor-version":[{"id":613,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/609\/revisions\/613"}],"wp:attachment":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/media?parent=609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/categories?post=609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/tags?post=609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}