-2

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);
    }
Nishad Arora
  • 304
  • 1
  • 5
  • 12

1 Answers1

2

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

var samples: [CMSampleBuffer] = []
while let sample = readerOutput.copyNextSampleBuffer() {
    samples.append(sample)
}
OOPer
  • 47,149
  • 6
  • 107
  • 142
  • THANK YOU so much,I was just reading that CFRelease is not needed anymore don't understand why? – Nishad Arora Jul 07 '16 at 11:18
  • Maybe you have heard about ARC. Swift ARC can take care of CF objects as well as NSObjects. You have no need to worry about CFRelease or what bridging attribute needed or something like those. In most cases, just removing all CFReleases would work. – OOPer Jul 07 '16 at 11:34
  • @Per oh great thank you so much – Nishad Arora Jul 07 '16 at 12:22