Nishad Arora Nishad Arora - 1 year ago 96
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)

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


Answer Source

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

var samples: [CMSampleBuffer] = []
while let sample = readerOutput.copyNextSampleBuffer() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download