Post

Replies

Boosts

Views

Activity

Dangling pointer warnings
The following code reads data from a file and populates the properties of the provided FileHeader struct. The code works, but every time I initialize the 'pointer' with a UnsafeMutableRawBufferPointer I get the'dangling buffer pointer' warning. I assume I need to use this within a 'withUnsafeBytes' closure somehow, but I can't seem to get the syntax right, despite a day of searching the internet for examples and fiddling with the bits. My head hurts. Any suggestions on how to modify this code to eliminate the warnings?  Many thanks in advance.      private func loadFileHeader( fileHandle: FileHandle, fileHeader: inout FileHeader ) {         var pointer: UnsafeMutableRawBufferPointer         pointer = UnsafeMutableRawBufferPointer(start: &fileHeader.fileCode, count: 4)     // *         fileHandle.readData(ofLength: 4).copyBytes(to: pointer)         fileHeader.fileCode = fileHeader.fileCode.bigEndian         SeekTo(fileHandle: fileHandle, offset: 24)         pointer = UnsafeMutableRawBufferPointer(start: &fileHeader.fileLength, count: 4)   // *         fileHandle.readData(ofLength: 4).copyBytes(to: pointer)         fileHeader.fileLength = fileHeader.fileLength.bigEndian // etc... } // * ==> Initialization of 'UnsafeMutableRawBufferPointer' results in a dangling buffer pointer
9
0
4.1k
Jul ’20
Replacements for NSOpenPanel & NSSavePanel
With NSOpenPanel and NSSavePanel gone what is equivalent functionality? I've found this snippet of code which seems similar to NSOpenPanel: let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String], in: .open) (I don't know how to get to the kUTTypeFolder constant, I only found it defined in a .h file, so this generates an error - I haven't actually executed this snippet yet) I actually need NSSavePanel - is there a comparable function to UIDocumentPickerViewController which would do the job? If anyone has addressed this issue I'd love to see your solution!
8
0
2.3k
Jun ’20