ios - How to write this void objective-c function in swift -
i've found code want utilize in swift ios app i'm having problem writing swift way.
-(void) captureoutput:(avcaptureoutput*)captureoutput didoutputsamplebuffer:(cmsamplebufferref)samplebuffer fromconnection:(avcaptureconnection*)connection { cvimagebufferref imagebuffer = cmsamplebuffergetimagebuffer( samplebuffer ); cgsize imagesize = cvimagebuffergetencodedsize( imagebuffer ); // in 'mediaspecific' dict of samplebuffer nslog( @"frame captured @ %.fx%.f", imagesize.width, imagesize.height ); }
it's function declaration i'm having problem with, contents of function should easier. i'm not used syntax of:
-(void) captureoutput:(avcaptureoutput*)captureoutput didoutputsamplebuffer:(cmsamplebufferref)samplebuffer fromconnection:(avcaptureconnection*)connection
my attempt:
i started trying write when nil autocomplete within ()
realised wrong:
func captureoutput(avcaptureoutput(didoutputsamplebuffer:)) { }
you can find right declaration in avcapturevideodataoutputsamplebufferdelegate protocol reference, declared this:
optional func captureoutput(_ captureoutput: avcaptureoutput!, didoutputsamplebuffer samplebuffer: cmsamplebuffer!, fromconnection connection: avcaptureconnection!)
you wouldn't write optional
in method definition, though:
class mydelegate: nsobject, avcapturevideodataoutputsamplebufferdelegate { func captureoutput(captureoutput:avcaptureoutput, didoutputsamplebuffer samplebuffer:cmsamplebuffer, fromconnection connection:avcaptureconnection) { allow imagebuffer = cmsamplebuffergetimagebuffer(samplebuffer) allow imagesize = cvimagebuffergetencodedsize(imagebuffer) nslog("frame captured @ %.fx%.f", imagesize.width, imagesize.height) } }
ios objective-c function swift
No comments:
Post a Comment