type A requires that type B be a class type swift 4

You can’t have a WeakReference<ServiceDelegate>. ServiceDelegate itself is not an AnyObject, it just requires that anything that conforms to it be an AnyObject. You would need to make SomeClass generic and use the generic type as the type for the WeakReference: class SomeClass<T: ServiceDelegate> { private var observers = [WeakReference<T>]() } If the generic on … Read more

Cannot convert value of type NSAttributedString.DocumentAttributeKey to .DocumentReadingOptionKey

You need to pass one of the available NSAttributedString DocumentType options: Hypertext Markup Language (HTML) document. static let html: NSAttributedString.DocumentType Plain text document. static let plain: NSAttributedString.DocumentType Rich text format document. static let rtf: NSAttributedString.DocumentType Rich text format with attachments document. static let rtfd: NSAttributedString.DocumentType In this case you will need to pass the first … Read more

How to fix “Read-Write-Data Sandbox: error when using Mac Catalyst

MasterChief96, you are not alone. Here is my setup: MacOS 10.15.3 Xcode 11.4.1 I create a brand new SwiftUI “Hello World” project, enable Mac as a target device, a.k.a. Catalyst. I set the iOS deployment target to 13.2 (otherwise I get a MacOS runtime error saying I need Catalina 10.15.4) Set the scheme to “My … Read more

How to conform UIImage to Codable?

Properly the easiest way is to just make the property Data instead of UIImage like this: public struct SomeImage: Codable { public let photo: Data public init(photo: UIImage) { self.photo = photo.pngData()! } } Deserialize the image: UIImage(data: instanceOfSomeImage.photo)!

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

iOS view visibility gone

As I have worked on both iOS & Android, You need to play with constraint outlet in ios to achieve Android functioning. iOS Does not support automatically like Android native support on visibility GONE & VISIBLE You need to hook the outlet of particular constraint(it may vertical/horizontal/height) you need to set it to 0 & … Read more