0

I am getting a UnsafeMutablePointer<CGPoint> that points to an array of one or two elements, I would like to build a Swift function converting UnsafeMutablePointer<CGPoint> to CGPoint that wouldn't require me to specify the expected size of the array, is it possible ?

Thank you

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Pop Flamingo
  • 3,023
  • 2
  • 26
  • 64
  • No. In contrast to UnsafeMutableBufferPointer (compare e.g. http://stackoverflow.com/questions/31106427/unsafemutablepointeruint8-to-uint8-without-memory-copy), UnsafeMutablePointer is just a pointer (quite similar to a C pointer) and does not have any information about the number of elements that it points to. – Martin R May 26 '16 at 10:00
  • @MartinR Thank you ! So the only solution is to know the size in advance ? – Pop Flamingo May 26 '16 at 10:02
  • 2
    Yes. UnsafeMutablePointer is just a memory address, nothing more. – Martin R May 26 '16 at 11:18
  • Perhaps you could provide a code context that yields you `UnsafeMutablePointer` and that could be redone. – Kamil.S Dec 29 '18 at 21:07

0 Answers0