Movatterモバイル変換


[0]ホーム

URL:


Friday,September4,2015

Struct Semantics in Swift

Chris Eidhof:

Instead, we can change ourmutableData accessor to prevent copying when there are no other references to thedata variable. To do this, we need to check if the data is uniquely referenced. In other words, we only make a copy of the data if the data is shared. We can do this using theisUniquelyReferencedNonObjC function. This is the reason why we needBox: it only works on Swift classes.NSMutableData is an Objective-C class, and then the function doesn't work.

[…]

Now we have full copy semantics, and efficient behavior: only when a copy is really necessary, it is made. This way, we never have to remember to writedata.copy() ourselves, we implemented it correctly once and can then forget about it.

CommentsRSS ·Twitter

Leave a Comment

  

Black Friday
Blog
Archives
Tag Cloud
Top Posts

Recently Updated
RSS Feed ·Comments
Mastodon ·Twitter
Apple News
Trackback

Support this site viaPatreon.

Try my Mac apps:

DropDMGDropDMGDropDMG
EagleFilerEagleFilerEagleFiler
SpamSieveSpamSieveSpamSieve
ToothFairyToothFairyToothFairy
Copyright © 2000–2025Michael Tsai.

[8]ページ先頭

©2009-2025 Movatter.jp