- Reactive Programming with Swift 4
- Navdeep Singh
- 127字
- 2021-06-24 18:57:58
Reserving capacity
Dictionary and sequence now have the capacity to explicitly, unambiguously reserve capacity.
Suppose you have a sequence of friends with an initial capacity of 4:
friends.capacity // 4
You can now reserve the capacity by doing this:
friends.reserveCapacity(20)
This reserves a minimum of 20 segments of capacity:
friends.capacity // 20
Reallocating memory to objects can be an expensive task, and if you have an idea about how much space it will require to store an object, then using reserveCapacity(_:) can be an easy and simple way to increase performance.
Swift 4 brings in a number of modifications to the Dictionary, 12 to be exact as per the official Apple developers guide, and a number of additions that we will discuss in subsequent sections:

推薦閱讀
- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- 微服務設計(第2版)
- 軟件安全技術
- Rust編程從入門到實戰
- Spring Boot+Spring Cloud+Vue+Element項目實戰:手把手教你開發權限管理系統
- 數據結構簡明教程(第2版)微課版
- Java程序設計與實踐教程(第2版)
- QTP自動化測試進階
- Cocos2d-x學習筆記:完全掌握Lua API與游戲項目開發 (未來書庫)
- WebRTC技術詳解:從0到1構建多人視頻會議系統
- Mastering Git
- Kubernetes進階實戰
- Python Web自動化測試設計與實現
- Clojure Polymorphism
- C++17 By Example