Last active
February 18, 2020 03:40
-
-
Save mvnrc/4373e6ab17f632623e1b98c93e49f9a3 to your computer and use it in GitHub Desktop.
An extension of UnsafeMutablePointer for converting C array to Swift array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UnsafeMutablePointer { | |
/// Converts `C` decayed array to `Swift` array | |
/// | |
/// - Parameter count: Number of elements in the `C` array | |
/// - Returns: Converted `Swift` array | |
public func toArray(count: Int) -> [Pointee] { | |
defer { self.deallocate() } | |
return Array(UnsafeBufferPointer(start: self, count: count)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment