Questions tagged «unsafe-pointers»

3
警告:“ UnsafeBufferPointer <T>”的初始化会导致缓冲区指针悬空
在更新到Swift 5.2 / Xcode 11.4之后,出现以下代码警告: extension Data { init&lt;T&gt;(from value: T) { var value = value let pointer = UnsafeBufferPointer(start: &amp;value, count: 1) self.init(buffer: pointer) } func to&lt;T&gt;(type: T.Type) -&gt; T { return self.withUnsafeBytes { $0.load(as: T.self) } } } 在网上让指针= UnsafeBufferPointer(开始:&值,计数:1)我得到了 初始化“ UnsafeBufferPointer”会导致缓冲区指针悬空 我可以使用@silenceWarning,但这是肮脏的解决方案。也许我需要将指针存储在某个地方并在将来进行清理?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.