Filling vertex buffer using Swift and Metal

I am sure this is an elementary question, but I am new to Swift and Metal, but have a fair amount of experience using Objective C and OpenGL.

I would like to render some mathematically generated surfaces in Metal and need to fill the vertex buffer with positions and normals. I would guess that creating a one dimensional array and adding to it using "append" is not the most efficient way to do this. The buffer might be quite large and I would like to set aside the memory for it in advance, which is how I did it using Objective C. Can anyone suggest the best way to do this? Thanks in advance.

A solution which worked very well is:

var vertexArray = Array<Float>(repeating: 0.0, count: <# of elements>)

I suppose that Swift is not used very much for numerical computation - this problem does not exist with other languages like Fortran of flavors of C. The few hits when I searched either thought it was not possible to do this or gave extremely complicated solutions.

Filling vertex buffer using Swift and Metal
 
 
Q