Nishad Arora Nishad Arora - 5 months ago 17
Objective-C Question

I am unable to convert this objectiveC code into swift

1.I am converting a reverse audio function of objective c into swift so that I can integrate the swift code into my program but these few lines of codes are not understandable

2.This is the following objective-c code:

CMSampleBufferRef sample;

NSMutableArray *samples = [[NSMutableArray alloc] init];

while (sample != NULL) {
sample = [readerOutput copyNextSampleBuffer];

if (sample == NULL)
continue;

[samples addObject:(__bridge id)(sample)];

CFRelease(sample);
}

Answer

The code you have shown can be converted to Swift as:

var samples: [CMSampleBuffer] = []
while let sample = readerOutput.copyNextSampleBuffer() {
    samples.append(sample)
}