> On Oct 5, 2015, at 1:42 PM, Jens Alfke <j...@mooseyard.com> wrote: > > The problems in this thread seem to stem from missing or incorrect > annotations in one Cocoa class (CIFilter IIRC; I don’t have the whole thread > in front of me.)
AVCaptureDevice, actually, but this is exactly it. The problem is that Apple hasn’t gotten to annotating AVCaptureDevice.h yet for Swift interop; in their defense, auditing all of the system frameworks for nullability and collection types is a big task that understandably will take some time to complete. With that said, the offending method is declared like this: + (NSArray *)devices; whereas for Swift interoperability, it should probably be declared like this instead: + (nonnull NSArray <AVCaptureDevice *> *)devices; Once Apple updates the header, the code in the OP should probably work as is without modification. In the meantime, Swift has to assume that the return type is [AnyObject]?, since it can’t know what type the array is supposed to contain, nor whether the array can be nil. The workaround is to explicitly cast and unwrap the array, like so: if let devices = AVCaptureDevice.devices() as? [AVCaptureDevice] { for device in devices { print("Device: \(device)") for f in device.formats { print(" format: \(f)") } } } which should work great. So, it’s not necessarily “Swift sucking” in this case, but rather some of the ObjC header files needing an update. With properly annotated ObjC header files, I’ve found that interop between Swift and ObjC has gotten fairly comfortable in Swift 2.0 / Xcode 7, with the exception of APIs that return non-type-specific values by reference (I’m looking at you, -[NSURL getResourceValue:forKey:error:]). Charles _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com