Unsafe***Pointer results in a dangling pointer という警告の回避方法
いつの間にやらXcodeが
Initialization of 'Unsafe***Pointer' results in a dangling pointer
という警告を出すようになってた。
どうもXcode 11.4で変わったそうだ。
Xcode 11.4 Release Notes | Apple Developer Documentation
↑確かに今後警告出す、とある。
動いてはいるが気持ち悪いので警告が出ないようにしたかったが回避方法をいくら調べても見つからず、、、
結局UnsafeRawPointerを使わずに記述した。
元々は
元はObjective-Cのコードを移植したからポインタ使ってたけどSwiftだとこういう記述でいいみたい。
ちなみに上記のコードはGitHubにアップしてたこちらのもの↓
YamaguchiTatsuya/ApproximateCurveAndPlane: Sample code to calculate approximate curve and plane using Least squares method and Gauss-Jordan elimination in Swift, macOS
修正したのをpushした(つもり)。
※1)Stack Overflowより
swift - Warning: Initialization of 'UnsafeBufferPointer<T>' results in a dangling buffer pointer - Stack Overflow
macOS 10.15.4 Catalina
Xcode 11.4
Swift 5.2
Initialization of 'Unsafe***Pointer' results in a dangling pointer
という警告を出すようになってた。
どうもXcode 11.4で変わったそうだ。
Xcode 11.4 Release Notes | Apple Developer Documentation
↑確かに今後警告出す、とある。
let p = UnsafeRawPointer(hoge)自分の場合、↑このようにしてポインタを得ているのだが、このpが次の行にはあるかどうかわかんねえぞ、というものらしい。とStack overflowにはある(※1)が、アプリは普通に動いてる。たまたまなんだろうか?
動いてはいるが気持ち悪いので警告が出ないようにしたかったが回避方法をいくら調べても見つからず、、、
結局UnsafeRawPointerを使わずに記述した。
元々は
func hoge(_ vertices: [vector_float3], …) {としていた。これをUnsafeRawPointerを使わずに、、、
let nofDots = vertices.count
let p = UnsafeRawPointer(vertices)
let data = Data(bytes: p , count: nofDots*MemoryLayout.size)
let data = Data(bytes: vertices ,とした。ああ、これでいいのね、、、
count: nofDots*MemoryLayout.size)
元はObjective-Cのコードを移植したからポインタ使ってたけどSwiftだとこういう記述でいいみたい。
ちなみに上記のコードはGitHubにアップしてたこちらのもの↓
YamaguchiTatsuya/ApproximateCurveAndPlane: Sample code to calculate approximate curve and plane using Least squares method and Gauss-Jordan elimination in Swift, macOS
修正したのをpushした(つもり)。
※1)Stack Overflowより
swift - Warning: Initialization of 'UnsafeBufferPointer<T>' results in a dangling buffer pointer - Stack Overflow
macOS 10.15.4 Catalina
Xcode 11.4
Swift 5.2
スポンサーサイト
<< xibファイル内に置いたUILabelにアクセスできない TopPage 最小二乗法で近似曲線/平面を得る(Swift) >>
トラックバック
トラックバックURL
https://ringsbell.blog.fc2.com/tb.php/1343-464fd1ea
https://ringsbell.blog.fc2.com/tb.php/1343-464fd1ea