I am unable to convert this objectiveC code into swift

72 Views Asked by At

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);
    }
1

There are 1 best solutions below

3
OOPer On BEST ANSWER

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

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