unsafemutablepointer

Dereference UnsafeMutablePointer<UnsafeMutableRawPointer>

天大地大妈咪最大 提交于 2020-02-05 08:45:49
问题 I have a block that is passing data in that I'd like to convert to an array of array of floats -- e.g. [[0.1,0.2,0.3, 1.0], [0.3, 0.4, 0.5, 1.0], [0.5, 0.6, 0.7, 1.0]]. This data is passed to me in the form of data:UnsafeMutablePointer<UnsafeMutableRawPointer> (The inner arrays are RGBA values) fwiw -- the block parameters are from SCNParticleEventBlock How can I dereference data into a [[Float]]? Once I have the array containing the inner arrays, I can reference the inner array (colorArray)

Dereference UnsafeMutablePointer<UnsafeMutableRawPointer>

大城市里の小女人 提交于 2020-02-05 08:44:25
问题 I have a block that is passing data in that I'd like to convert to an array of array of floats -- e.g. [[0.1,0.2,0.3, 1.0], [0.3, 0.4, 0.5, 1.0], [0.5, 0.6, 0.7, 1.0]]. This data is passed to me in the form of data:UnsafeMutablePointer<UnsafeMutableRawPointer> (The inner arrays are RGBA values) fwiw -- the block parameters are from SCNParticleEventBlock How can I dereference data into a [[Float]]? Once I have the array containing the inner arrays, I can reference the inner array (colorArray)

In Swift 3.1, UnsafeMutablePointer.initialize(from:) is deprecated

穿精又带淫゛_ 提交于 2020-01-14 14:55:27
问题 In Swift 3.1, UnsafeMutablePointer.initialize(from:) is deprecated. Xcode suggests I use UnsafeMutableBufferPointer.initialize(from:) instead. I have a code block that looks like this: let pointer = UnsafeMutablePointer<UInt8>.allocate(capacity: 64) pointer.initialize(from: repeatElement(0, count: 64)) The code gives me a compile time warning because of the deprecation. So I'm going to change that to: let pointer = UnsafeMutablePointer<UInt8>.allocate(capacity: 64) let buffer =

Swift 3 - Pass struct by reference via UnsafeMutableRawPointer?

孤人 提交于 2020-01-04 07:51:49
问题 In the Core Audio -Framework user data can be passed into callbacks via an UnsafeMutableRawPointer? . I was wondering how to pass a struct by reference via this UnsafeMutableRawPointer? . Changes made inside the callback should be reflected outside the callback. I set up a playground to test this: struct TestStruct { var prop1: UInt32 var prop2: Float64 var prop3: Bool } func printTestStruct(prefix: String, data: TestStruct) { print("\(prefix): prop1: \(data.prop1), prop2: \(data.prop2),

Swift 3 - Pass struct by reference via UnsafeMutableRawPointer?

房东的猫 提交于 2020-01-04 07:51:02
问题 In the Core Audio -Framework user data can be passed into callbacks via an UnsafeMutableRawPointer? . I was wondering how to pass a struct by reference via this UnsafeMutableRawPointer? . Changes made inside the callback should be reflected outside the callback. I set up a playground to test this: struct TestStruct { var prop1: UInt32 var prop2: Float64 var prop3: Bool } func printTestStruct(prefix: String, data: TestStruct) { print("\(prefix): prop1: \(data.prop1), prop2: \(data.prop2),

Testcase failed after converting codes from Objective-C to Swift

╄→гoц情女王★ 提交于 2020-01-03 15:16:11
问题 I am doing some bitwise operations in Swift style, which these codes are originally written in Objective-C/C. I use UnsafeMutablePointer to state the beginning index of memory address and use UnsafeMutableBufferPointer for accessing the element within the scope. You can access the original Objective-C file Here. public init(size: Int) { self.size = size self.bitsLength = (size + 31) / 32 self.startIdx = UnsafeMutablePointer<Int32>.alloc(bitsLength * sizeof(Int32)) self.bits =

Using C functions in Swift that take functions as arguments

十年热恋 提交于 2020-01-01 12:13:17
问题 I'm writing a wrapper around a C mathematical library. Every function takes one or two functions as arguments. However, the arguments for those child functions (as well as the parent functions) are not Swifty -hence the wrapper. I've cleaned up the example code to just show the three main pieces: the c-library function, the desired Swift function that would be passed to the wrapper (body not shown, but wrapping around the c-library function), and the required C function form. //C library

How do you satisfy the 'lineOrigins' argument in CTFrameGetLineOrigins() in Swift? [duplicate]

一曲冷凌霜 提交于 2019-12-23 04:12:36
问题 This question already has an answer here : Issue with CoreText CTFrameGetLineOrigins in Swift (1 answer) Closed last year . I'm trying to figure out CTFrameGetLineOrigins from here: CTFrameGetLineOrigins Got Incorrect Origins, and trying to convert the ObjC to Swift. Obj-C: CFArrayRef lines = CTFrameGetLines(frame); size_t numOfLines = CFArrayGetCount(lines); CGPoint lineOrigins[numOfLines]; CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins); Swift: let lines = CTFrameGetLines(frame

Swift 3 UnsafeMutablePointer initialization for C type float**

允我心安 提交于 2019-12-13 04:00:02
问题 Within Swift 3, I need to send data to a C object accepting float ** input. In Swift 2, I used to declare a UnsafeMutablePointer< UnsafeMutablePointer<Float32>> , construct a swift Array (only for init!), and pass this to the pointer, and it worked: var bufferOut: UnsafeMutablePointer< UnsafeMutablePointer<Float32>>? arrayOut = Array(repeating: Array(repeating: 0, count: Int(size1), count: Int(size2)) bufferOut = UnsafeMutablePointer< UnsafeMutablePointer<Float32>>(arrayOut) This is all

Objective-C pointer and swift

左心房为你撑大大i 提交于 2019-12-12 04:37:13
问题 I'm following an apple document, but unfortunately the examples are written on objective-c, but I have confidence with Swift language and can not understand the meaning of some things, in particular, in this example: void RunLoopSourcesPerformRoutine (void *info){ RunLoopSource* obj = (RunLoopSource*)info; [obj sourceFired]; } this line: RunLoopSource* obj = (RunLoopSource*)info; the parameter: void *info indicates that info is a pointer to void, then I can put the address of any type of data