Package.swift
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "CaptureSDK",
products: [
Package.swift
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "CaptureSDK",
products: [
guard let filter = CIFitler(name: "CIBlendWithMask") else { | |
// Could not find the built-in filter | |
return nil | |
} | |
let backgroundImage = CIImage(color: .clear).cropped(to: inputImage.extent) | |
filter.setValue(backgroundImage, forKey: kCIInputBackgroundImageKey) | |
filter.setValue(inputImage, forKey: kCIInputImageKey) | |
filter.setValue(maskImage, forKey: kCIInputMaskImageKey) | |
return filter.outputImage |
let myKernel = try CIKernel(functionName: "doNothing") |
import CoreImage | |
import Metal | |
private func defaultMetalLibrary() throws -> Data { | |
let url = Bundle.main.url(forResource: "default", withExtension: "metallib")! | |
return try Data(contentsOf: url) | |
} | |
extension CIKernel { | |
/// Init CI kernel with just a `functionName` directly from default metal library |
import CoreImage | |
class AlphaFrameFilter: CIFilter { | |
static var kernel: CIColorKernel? = { | |
return CIColorKernel(source: """ | |
kernel vec4 alphaFrame(__sample s, __sample m) { | |
return vec4( s.rgb, m.r ); | |
} | |
""") | |
}() |
#import "LeakTest.h" | |
#import "FailingObject.h" | |
@interface LeakTest () | |
@property (nonatomic, strong) FailingObject *object; | |
@end | |
@implementation LeakTest | |
- (void)performFailure { |
// CatchingException.swift | |
{ | |
let failingObject = MyFailingObject() | |
if let exception = objc_tryCatch({ failingObject.throwException() }) { | |
// Here we caught the exception, but we actually leaked failingObject | |
} | |
// Let's check that it's actually leaking |
// MyFailingObject.m | |
@implementation MyFailingObject | |
- (void)throwException { | |
@throw [NSException exceptionWithName:NSGenericException | |
reason:@"An exception on purpose" | |
userInfo:nil]; | |
} |
// Given a block `let mayRaiseAnException: () -> Void` | |
if let exception = objc_tryCatch(mayRaiseAnException) { | |
// Here is your caugth exception | |
} |