I want to convert the following Apple's objc code to swift
_materialUniforms = [device newBufferWithLength:sizeof(AAPLMaterialUniforms) options:0];
AAPLMaterialUniforms *materialUniforms = (AAPLMaterialUniforms *)[_materialUniforms contents];I tried the following
self.materialUniforms = device.newBufferWithLength(sizeof(AAPLMaterialUniforms), options: .CPUCacheModeDefaultCache)
let materialUniforms = UnsafeMutablePointer<AAPLMaterialUniforms>(self.materialUniforms.contents())but it is reallocating, I tried many other things without success
Thank you in advance
C-languages `->` is sort of combined operator of dereferencing pointer (prefix `*`) and accessing field (`.`).
So, line 03 of your Swift code lacks "dereferencing pointer" operation. In Swift, you use `.memory` (this will change in Swift 3) to dereference pointer.
materialUniforms.memory.specularColor = property.float4ValueIn most cases (Objective-)C's `->` can be converted to Swift's `.memory.`, if you convert pointer types appropriately.