I want to translate to following objective-c code to Swift:
+ (void)someClassFunction {
__weak __typeof(self)weakSelf = self;
}
My result would be:
class func someClassFunction() {
var weakSelf = self
}
The problem is that I cannot apply weak
inside a method.
How can I make a weak reference to self in class function in Swift?
Here is the code I want to translate:
__weak __typeof(self)weakSelf = self;
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [UIImage imageWithData:imageData];
UIImage *croppedImage = [weakSelf cropImage:image withCropSize:cropSize];
completion(croppedImage);
}
}];
+ (UIImage *)cropImage:(UIImage *)image withCropSize:(CGSize)cropSize
{
...
}
Edit:
Do I really need the week reference in Swift or can I just do the following?
ClassName.cropImage(...)