Community

[Swift] Dictionary.mapValuesWithKeys로 성능 개선하기

SE-0510에서 제안된 mapValuesWithKeys는 dictionary 값을 변환할 때 key 정보도 함께 사용할 수 있게 해줍니다. 지금까지는 init(uniqueKeysWithValues:)나 reduce(into:)를 써야 했는데, 불필요하게 전체 dictionary를 rehashing하는 비용이 발생했어요. 새로운 메서드는 key를 transformation closure에 전달하면서도 rehashing 없이 값만 효율적으로 변환합니다. Currency 같은 enum을 key로 쓰면서 display text를 만드는 경우처럼, key가 formatting context를 제공하는 흔한 패턴에서 특히 유용할 것 같습니다 😃 https://green1229.tistory.com/610

알림

알림이 없습니다