From 77a0878f8d0144a3d7053fed9a955274b51e3eaf Mon Sep 17 00:00:00 2001 From: Marius Horga Date: Tue, 31 Oct 2017 23:18:30 -0500 Subject: [PATCH] updated to Swift 4 --- .../particle2.playground/Sources/MetalViewDelegate.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/particles/particle2.playground/Sources/MetalViewDelegate.swift b/particles/particle2.playground/Sources/MetalViewDelegate.swift index 212a1b3..4ae81f5 100644 --- a/particles/particle2.playground/Sources/MetalViewDelegate.swift +++ b/particles/particle2.playground/Sources/MetalViewDelegate.swift @@ -26,18 +26,15 @@ public class MetalViewDelegate: NSObject, MTKViewDelegate { particles = [Particle](repeatElement(Particle(), count: 1000)) particlesBuffer = device.makeBuffer(length: particles.count * MemoryLayout.stride, options: [])! var pointer = particlesBuffer.contents().bindMemory(to: Particle.self, capacity: particles.count) - for _ in particles.enumerated() { + for _ in particles { pointer.pointee.initialMatrix = translate(by: [Float(drand48()) / 10, Float(drand48()) * 10, 0]) pointer.pointee.color = float4(0.2, 0.6, 0.9, 1) pointer = pointer.advanced(by: 1) } let allocator = MTKMeshBufferAllocator(device: device) let sphere = MDLMesh(sphereWithExtent: [0.01, 0.01, 0.01], segments: [8, 8], inwardNormals: false, geometryType: .triangles, allocator: allocator) - do { - model = try MTKMesh(mesh: sphere, device: device) - } catch let e { - Swift.print("\(e)") - } + do { model = try MTKMesh(mesh: sphere, device: device) } + catch let e { print(e) } } func initializeMetal() {