Apple プロダクト向けのプログラミング言語 Swift の解説書。
本書のコード例でいくつか実験した。なお、本書は初版であり、2022 年 12 月現在は第3版まで出ているので、 実験結果は異なることがあるかもしれない(私は第3版を持っていないし、また見てもいない)。環境は、 WSL2 の Ubuntu 22.04 上の Swift 5.7.2 である。
pp.271-272 のデリゲートパターンでは、次の警告が表示される。
$ swift delegate.swift delegate.swift:5:25: warning: using 'class' keyword to define a class-constrained protocol is deprecated; use 'AnyObject' instead protocol GameDelegate : class { ^~~~~ AnyObject Number of players is 2 Game start Playing Game end
警告にあるとおり、class のかわりに AnyObject を使えば問題なく動作する。
12.2 節は GCD を使った非同期処理の方法について示されている。p.297 の最初のコードを実験した。import PlaygourndSupport の行は省いた。次の警告が出る。
$ swift async.swiftasync.swift:9:9: warning: initialization of immutable value 'isMainThread' was never used; consider replacing with assignment to '_' or removing it let isMainThread = Thread.isMainThread // false ~~~~^~~~~~~~~~~~ _ 非同期の処理
それはそうである。私はこの行の直後に print("\(isMainThread)")を入れてみた。これで警告は出なくなる。
書名 | Swift 実践入門 |
著者 | 石川洋資、西山勇世 |
発行日 | 2017 年 2 月 21 日 初版第 1 刷 |
発行元 | 技術評論社 |
定価 | 3200円(税別) |
サイズ | |
ISBN | 978-4-7741-8730-3 |
備考 | 越谷市立図書館で借りて読む |
NDC | 007.6 |
まりんきょ学問所 > コンピュータの部屋 > コンピュータの本 > Swift > 石川洋資、西山勇世 : Swift 実践入門