Twitterでふぁぼったものをひたすら試します

Swift evolution proposals No.268 - No.273を読んだだけ

qiita.com

2019年の感想:
上半期は UICollectionView を軽くやって下半期はDark ModeをやってたのでSwiftのことはすっかり忘れました。マジで何もわからん。Swift5さえ怪しい気がする。

なのでここ1ヶ月のproposalを軽く読んでアドベントカレンダーをごまかす。
No.268〜No.273です

Refine didSet Semantics

swift-evolution/0268-didset-semantics.md at master · apple/swift-evolution · GitHub
今のステータス:Active Review (5-9 December 2019)

今のSwiftは、 didSet が動くと oldValue の取得をするために毎回getしちゃうらしい。たとえ oldValue を使わなくてもallocateしたりしちゃうらしい。
このproposalは 「oldValue を使わない時はその辺の処理をスキップしたい!」というもの。

Increase availability of implicit self in @escaping closures when reference cycles are unlikely to occur

swift-evolution/0269-implicit-self-explicit-capture.md at master · apple/swift-evolution · GitHub
今のステータス:Accepted

self の書き方が変わるっぽい。

class Test {
    var x = 0
    func execute(_ work: @escaping () -> Void) {
        work()
    }
    func method() {
        execute { [self] in
            x += 1  // ← [self]って明示したからself.xって書かなくていいことにする
        }
    }
}
struct Test {
    var x = 0
    func execute(_ work: @escaping () -> Void) {
        work()
    }
    func method() {
        execute { 
            x += 1  // ←この場合、selfはstruct(値型)なんだから[self]って明示する必要もないでしょ
        }
    }
}

今は不要なところでも self.x って書いてるし、Appleは不要なselfは書かない方針のようなので必要なところだけ明示するようにする。

Add Collection Operations on Noncontiguous Elements

swift-evolution/0270-rangeset-and-collection-operations.md at master · apple/swift-evolution · GitHub
今のステータス:Active review (December 13th...19th, 2019)

IndexSet 以外に RangeSet を増やしたいというproposal。

numbers = Array(1...15)
let notTheMiddle = RangeSet([0..<5, 10..<15])

print(Array(numbers[notTheMiddle]))
// Prints [1, 2, 3, 4, 5, 11, 12, 13, 14, 15]

Package Manager Resources

swift-evolution/0271-package-manager-resources.md at master · apple/swift-evolution · GitHub
今のステータス:Accepted with revisions

一言でいえばタイトル通り。SPMなので、もちろんプラットフォームに依存しない形で。

目標をざっくり訳すと

  • 簡単にリソースファイルを追加できるようにする
  • リソースではないファイル(ドキュメントなど)を間違えて混入しないようにする
  • プラットフォーム依存のもの(xibとか)も対応する
  • ローカライゼーションも。
  • package authorが好きなところにリソースファイルをおけるようにする

とのこと。

Package Manager Binary Dependencies

swift-evolution/0272-swiftpm-binary-dependencies.md at master · apple/swift-evolution · GitHub
今のステータス:Accepted with revisions

これも一言でいえばタイトル通り。

CocoaPodsみたいにクローズドソース(Firebaseとかそういうの)に対応できるようにしたいというのがモチベ。

ただ、以下のことをやるつもりはないらしい(バイナリでできたものについて詳しくないからよくわかんない。。)

  • Ease of production of binary packages
  • Simplicity of binary artifact distribution mechanism
  • Widespread use of binary packages

あと、proposalには「最初はAppleのプラットフォーム対応だけ」と書いてあるので今後に期待する要素がそれなりにありそう。

Package Manager Conditional Target Dependencies

swift-evolution/0273-swiftpm-conditional-target-dependencies.md at master · apple/swift-evolution · GitHub
今のステータス:Accepted

targetのdependencycondition: が増えるらしい。

            dependencies: [
                .product(name: "Bluetooth", condition: .when(platforms: [.macOS])),
                .product(name: "BluetoothLinux", condition: .when(platforms: [.linux])),
                .target(name: "DebugHelpers", condition: .when(configuration: .debug)),
            ]

まとめ

SPMが集中してた