Simultaneous accesses to 0x1c0a7f0f8, but modification requires exclusive access error on Xcode 9 beta 4

I think this ‘bug’ may be a Swift 4 ‘feature’, specifically something they call ‘Exclusive access to Memory’. Check out this WWDC video. Around the 50 minute mark, the long-haired speaker explains it. https://developer.apple.com/videos/play/wwdc2017/402/?time=233 You could try turning the thread sanitizer off in your scheme settings if you’re happy to ignore it. However, the debugger … Read more

What is export * in module.modulemap file inside each framework?

Objective-C Module Map(.modulemap) for Objective-C and Swift Objective-C language exposes API thought .modulemap for Objective-C and Swift languages [ObjC Module] [Custom .modulemap] It is about LLVM Modules and Module Map Language. Modulemap exposes C header files for external binaries. It is a bridge between module and headers. Modulemap helps to convert #include, #import -> @import … Read more

Forced to cast, even if protocol requires given type

Adopting the protocol Fooable tells the compiler that this particular UIViewController responds to foo(), no less no more. In reverse conclusion Fooable does not become UIViewController necessarily. The constraint Self: UIViewController is just another information for the compiler to complain at compile time if the affected class is not UIViewController In your case when annotating … Read more

Barcode on swift 4

I figured it out but Apple didn’t make it so obvious. The callback function from the delegate AVCaptureMetadataOutputObjectsDelegate has been renamed and the parameter names are different! So, replace func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) to func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) My view controller is now … Read more

Swift JSONDecode decoding arrays fails if single element decoding fails

One option is to use a wrapper type that attempts to decode a given value; storing nil if unsuccessful: struct FailableDecodable<Base : Decodable> : Decodable { let base: Base? init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() self.base = try? container.decode(Base.self) } } We can then decode an array of these, with your … Read more

With JSONDecoder in Swift 4, can missing keys use a default value instead of having to be optional properties?

You can implement the init(from decoder: Decoder) method in your type instead of using the default implementation: class MyCodable: Codable { var name: String = “Default Appleseed” required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) if let name = try container.decodeIfPresent(String.self, forKey: .name) { self.name = name } } } You … Read more