Dynamically size array?
Super quick question, my initial thought 开发者_JAVA百科was this is not going to work, but then I thought why not give it a go. Now I am thinking it won't work as the resultant array does not seem to be properly formed? My question, should this work?
NSUInteger numPoints = [[[self dataModel] locationFake] count];
CLLocationCoordinate2D points[numPoints];
No, it wouldn't work as the points[]
array needs to be sized statically. That is, the compiler needs to know the size of that array, but can't possibly know it until runtime.
If you change it to:
CLLocationCoordinate2D *points = malloc(numPoints * sizeof(CLLocationCoordinate2D));
That should work. Just don't forget to free()
it later when you are done.
精彩评论