{"id":1480,"date":"2016-09-14T11:30:57","date_gmt":"2016-09-14T02:30:57","guid":{"rendered":"https:\/\/blog.ymyzk.com\/?p=1480"},"modified":"2016-10-08T18:33:19","modified_gmt":"2016-10-08T09:33:19","slug":"ios-10-swift-3-tips","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2016\/09\/ios-10-swift-3-tips\/","title":{"rendered":"Swift 3 \u3078\u306e\u79fb\u884c\u6642\u306b\u6c17\u4ed8\u3044\u305f\u3053\u3068"},"content":{"rendered":"
\u3053\u306e\u8a18\u4e8b\u3067\u306f\u65e2\u5b58\u306e iOS \u30a2\u30d7\u30ea\u3092 Swift 3 \u306b\u79fb\u884c\u3057\u305f\u6642\u306b\u6c17\u4ed8\u3044\u305f\u5e7e\u3064\u304b\u306e\u77e5\u898b\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059. \u81ea\u5206\u81ea\u8eab\u304c\u307e\u3060 iOS 10\u30fbSwift 3 \u306b\u3064\u3044\u3066\u7406\u89e3\u304c\u4e0d\u5341\u5206\u306a\u90e8\u5206\u3082\u3042\u308a\u307e\u3059\u304c, \u5c11\u3057\u3067\u3082\u53c2\u8003\u306b\u306a\u308c\u3070\u5e78\u3044\u3067\u3059.<\/p>\n
<\/p>\n
\u79fb\u884c\u4f5c\u696d\u3092\u884c\u3046\u524d\u306b Xcode 7.3.1 \u3068 iOS 9.3 SDK \u3067\u304d\u3061\u3093\u3068\u30a2\u30d7\u30ea\u304c\u30d3\u30eb\u30c9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046. \u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3064\u3044\u3066\u3082\u304d\u3061\u3093\u3068\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3057\u3066\u304a\u304f\u3068, \u5f8c\u3067\u4fee\u6b63\u3059\u308b\u90e8\u5206\u304c\u5c11\u306a\u304f\u3066\u6e08\u307f\u307e\u3059.<\/p>\n
iOS 10 SDK \u3092\u7528\u3044\u305f\u958b\u767a\u306b\u306f, Xcode 8 \u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059. \u307e\u305a\u306f Xcode \u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u3068\u3053\u308d\u304b\u3089\u59cb\u3081\u307e\u3057\u3087\u3046.<\/p>\n
Xcode 8 + iOS 10 SDK \u306e\u74b0\u5883\u3067\u306f Swift 2.3 \u3068 Swift 3 \u306e2\u3064\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306e Swift \u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059. Swift 2.3 \u306f Swift 2.2 \u304b\u3089\u306e\u30de\u30a4\u30ca\u30fc\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3067, Swift 2.2 \u304b\u3089\u6bd4\u8f03\u7684\u4f4e\u3044\u30b3\u30b9\u30c8\u3067\u79fb\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059. Swift 3 \u306f Swift 2.2 \u304b\u3089\u5927\u304d\u304f\u6539\u5584\u3055\u308c\u3066\u3044\u307e\u3059\u304c, \u79fb\u884c\u306b\u3042\u305f\u3063\u3066\u306f\u5927\u304d\u306a\u5909\u66f4\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059.<\/p>\n
\u6ce8\u610f\u3059\u3079\u304d\u70b9\u306f Swift 2.3 \u306f Swift 3 \u306f\u4e00\u3064\u306e\u30d0\u30a4\u30ca\u30ea\u306e\u4e2d\u3067\u6df7\u5728\u3055\u305b\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044<\/strong>\u3068\u3044\u3046\u70b9\u3067\u3059. \u5f8c\u8ff0\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u5bfe\u5fdc\u72b6\u6cc1\u3092\u542b\u3081, Swift 2.3 \u306b\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u306e\u304b, Swift 3 \u306b\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u306e\u304b\u3092\u8003\u3048\u307e\u3057\u3087\u3046.<\/p>\n \u5c06\u6765\u306e\u3053\u3068\u3092\u8003\u3048\u308b\u306a\u3089 Swift 3 \u306b\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u306e\u304c\u30d9\u30b9\u30c8\u3067\u3059\u304c, \u958b\u767a\u6642\u9593\u7b49\u306e\u90fd\u5408\u3067\u4e00\u65e6 Swift 2.3 \u306b\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3057, \u305d\u306e\u5f8c Swift 3 \u3078\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059.<\/p>\n \u306a\u304a, \u3053\u306e\u8a18\u4e8b\u3067\u306f\u57fa\u672c\u7684\u306b Swift 3 \u3078\u306e\u79fb\u884c\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059.<\/p>\n \u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u3042\u308c\u3070, \u305d\u308c\u3089\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c iOS 10\u30fbSwift 2.3 \/ 3 \u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u304b\u3092\u4e8b\u524d\u306b\u78ba\u8a8d\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046. \u30e1\u30b8\u30e3\u30fc\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u306f Swift 2.3 \u3068 Swift 3 \u306e\u30b3\u30fc\u30c9\u304c\u5225\u3005\u306e\u30d6\u30e9\u30f3\u30c1\u3067\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u304c, \u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3088\u3063\u3066\u306f Swift 3 \u306e\u307f\u306e\u5bfe\u5fdc\u3068\u306a\u3063\u3066\u3044\u308b\u3082\u306e\u3082\u3042\u308a, \u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059.<\/p>\n \u5bfe\u5fdc\u3059\u308b iOS \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3064\u3044\u3066\u3082\u691c\u8a0e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059. Xcode 8.0 \u3068 iOS 10 SDK \u3067\u306f iOS 8.0 \u4ee5\u964d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u8a2d\u5b9a\u51fa\u6765\u307e\u3059. \u307e\u305f, \u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306f, \u305d\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u5bfe\u5fdc\u3057\u3066\u3044\u308b deployment target \u306b\u3064\u3044\u3066\u3082\u610f\u8b58\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059.<\/p>\n iOS 10 \u3084 Swift 3 \u306b\u3064\u3044\u3066\u306e\u60c5\u5831\u3092\u4e8b\u524d\u306b\u53ce\u96c6\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046.<\/p>\n \u3053\u306e\u7bc0\u3067\u306f\u5b9f\u969b\u306b iOS 10\u30fbSwift 3 \u306b\u79fb\u884c\u3059\u308b\u969b\u306b\u884c\u3063\u305f\u4f5c\u696d\u3084, \u8e93\u3044\u305f\u70b9\u3092\u5e7e\u3064\u304b\u7d39\u4ecb\u3057\u307e\u3059. Swift 3 \u3067\u306e\u5909\u66f4\u306f\u3042\u307e\u308a\u306b\u591a\u304f\u3042\u308b\u305f\u3081, \u7279\u306b\u6c17\u306b\u306a\u3063\u305f\u3068\u3053\u308d\u3092\u5e7e\u3064\u304b\u7d39\u4ecb\u3057\u307e\u3059.<\/p>\n Swift 2.2 \u304b\u3089 Swift 2.3 \/ 3 \u3078\u306e\u79fb\u884c\u306b\u306f Xcode 8.0 \u306e migration assistant \u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059. \u3053\u308c\u3060\u3051\u3067\u5b8c\u5168\u306b\u79fb\u884c\u3059\u308b\u3053\u3068\u306f\u51fa\u6765\u307e\u305b\u3093\u304c, \u307e\u305a\u306f\u8a66\u3057\u3066\u307f\u308b\u4fa1\u5024\u306e\u3042\u308b\u6a5f\u80fd\u3060\u3068\u601d\u3044\u307e\u3059. \u5f53\u7136\u3067\u3059\u304c\u79fb\u884c\u306e\u524d\u5f8c\u3067 VCS \u7b49\u3067\u304d\u3061\u3093\u3068\u30b3\u30df\u30c3\u30c8\u3057\u3066\u304a\u304d, \u4fee\u6b63\u3055\u308c\u305f\u7b87\u6240\u304c\u308f\u304b\u308b\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059.<\/p>\n \u30e9\u30a4\u30d6\u30e9\u30ea\u3092 iOS 10\u30fbSwift 3 \u5bfe\u5fdc\u306e\u524d\u306b\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3057\u307e\u3059. Migration assistant \u306e\u5b9f\u884c\u524d\u306b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u306e\u304c\u826f\u3044\u304b, \u5b9f\u884c\u5f8c\u306b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\u306e\u304c\u826f\u3044\u304b\u306f\u30b1\u30fc\u30b9\u30d0\u30a4\u30b1\u30fc\u30b9\u3060\u3068\u601d\u3046\u306e\u3067, \u3046\u307e\u304f\u3044\u304f\u65b9\u3092\u8a66\u3059\u306e\u304c\u826f\u3055\u305d\u3046\u3067\u3059.<\/p>\n Swift 3 \u3067\u306f API \u306e\u30c7\u30b6\u30a4\u30f3\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3<\/a>\u304c\u5b9a\u3081\u3089\u308c\u3066\u3044\u307e\u3059. \u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306e API \u306b\u3082\u591a\u304f\u306e\u5909\u66f4\u304c\u52a0\u3048\u3089\u308c\u3066\u3044\u308b\u305f\u3081\u5bfe\u5fdc\u304c\u5fc5\u8981\u3067\u3059.<\/p>\n \u307e\u305f, Apple \u304c\u63d0\u4f9b\u3059\u308b GCD \u306a\u3069\u306e API \u3082\u591a\u304f\u306e\u5909\u66f4\u304c\u52a0\u3048\u3089\u308c, \u3088\u308a Swift \u3089\u3057\u304f\u306a\u3063\u3066\u3044\u307e\u3059. \u3053\u308c\u3089\u306b\u3064\u3044\u3066\u3082\u5bfe\u5fdc\u304c\u5fc5\u9808\u3067\u3059. GCD \u3067\u306e\u4f8b:<\/p>\n \u65e2\u5b58\u306e\u30b3\u30fc\u30c9\u306e API \u3082\u65b0\u3057\u3044\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u306b\u6cbf\u3063\u305f\u3082\u306e\u306b\u3059\u308b\u306e\u304c\u671b\u307e\u3057\u3044\u3067\u3059\u304c, \u3053\u308c\u3082\u5909\u66f4\u306b\u5927\u304d\u306a\u30b3\u30b9\u30c8\u304c\u304b\u304b\u308b\u306e\u3067, \u4e00\u65e6 Swift 3 \u3067\u30a2\u30d7\u30ea\u3092\u30d3\u30eb\u30c9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304b\u3089\u5bfe\u5fdc\u3057\u3066\u3082\u9045\u304f\u306a\u3044\u3068\u601d\u3044\u307e\u3059.<\/p>\n \u8fd4\u308a\u5024\u3092\u8fd4\u3059\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u3066\u3044\u308b\u306b\u3082\u304b\u304b\u308f\u3089\u305a, \u305d\u306e\u8fd4\u308a\u5024\u3092\u5229\u7528\u3057\u3066\u3044\u306a\u3044\u5834\u5408, Swift 3 \u306e\u30b3\u30f3\u30d1\u30a4\u30e9\u306f warning \u3092\u5410\u304d\u307e\u3059. Swift 2 \u3067\u306f \u3053\u306e warning \u3092\u6291\u5236\u3059\u308b\u306b\u306f, \u8fd4\u308a\u5024\u3092 \u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u9078\u5b9a<\/h3>\n
Deployment Target<\/h3>\n
\u60c5\u5831\u53ce\u96c6<\/h3>\n
\n
\u79fb\u884c\u4f5c\u696d<\/h2>\n
Migration Assistant<\/h3>\n
\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8<\/h3>\n
API \u95a2\u4fc2\u306e\u5909\u66f4<\/h3>\n
DispatchQueue.main.async {\r\n \/\/ Code here\r\n}<\/code><\/pre>\n
\u53c2\u8003<\/h4>\n
\n
\n
\u8fd4\u308a\u5024\u3092\u5229\u7528\u3057\u306a\u3044\u5834\u5408\u306e\u8b66\u544a<\/h2>\n
@warn_unused_result<\/code> \u3092\u3064\u3051\u308b\u3053\u3068\u3067\u540c\u69d8\u306e warning \u3092\u51fa\u3059\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f.<\/p>\n
_<\/code> \u306b\u4ee3\u5165\u3059\u308b\u304b, \u95a2\u6570\u306b
@discardableResult<\/code> \u3092\u3064\u3051\u307e\u3059. \u30b3\u30fc\u30c9\u306b\u3088\u3063\u3066\u306f\u3053\u306e warning \u304c\u5927\u91cf\u306b\u51fa\u3066\u3057\u307e\u3046\u306e\u3067, \u3046\u307e\u304f\u6291\u5236\u3057\u305f\u65b9\u304c\u4ed6\u306e\u8b66\u544a\u306b\u96c6\u4e2d\u3057\u3084\u3059\u304f\u306a\u308a\u307e\u3059. \u4f8b:<\/p>\n
func f(x: Int) -> Int {\r\n return x * 10\r\n}\r\n_ = f(10)\r\n\r\n@discardableResult func g(x: Int) -> Int {\r\n return x * 10\r\n}\r\ng(10)<\/code><\/pre>\n
\u53c2\u8003<\/h4>\n