Swift Codable Decode Manually Optional Variable
Age is optional: let age: String? So try to decode in this way: let age: String? = try values.decodeIfPresent(String.self, forKey: .age)
Age is optional: let age: String? So try to decode in this way: let age: String? = try values.decodeIfPresent(String.self, forKey: .age)
An update to Alex’s answer: In my case it was a React-Native project after adding a Swift Pods library. Maybe just the step 2 can work: Adding a new Swift file and a Brigde header: 1) File -> New -> File 2) Select Swift File 3) Confirm Create Bridging Header Go to Build Settings and … Read more
init(colorLiteralRed:green:blue:alpha:) is intended to be used with Color Literals which are managed by development tools. Why don’t you use normal init(red:green:blue:alpha:)? let startingColorOfGradient = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0).cgColor let endingColorOFGradient = UIColor(red: 251.0/255.0, green: 247.0/255.0, blue: 234.0/255.0, alpha: 1.0).cgColor let gradient: CAGradientLayer = CAGradientLayer() (Writing like 234.0/255.0 is not mandatory, in … Read more
In iOS 11, you should use like this : @available(iOS 11.0, *) func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) { let imageData = photo.fileDataRepresentation() }
You can use like this : enum DateError: String, Error { case invalidDate } let decoder = JSONDecoder() let formatter = DateFormatter() formatter.calendar = Calendar(identifier: .iso8601) formatter.locale = Locale(identifier: “en_US_POSIX”) formatter.timeZone = TimeZone(secondsFromGMT: 0) decoder.dateDecodingStrategy = .custom({ (decoder) -> Date in let container = try decoder.singleValueContainer() let dateStr = try container.decode(String.self) formatter.dateFormat = “yyyy-MM-dd’T’HH:mm:ss.SSSXXXXX” if … Read more
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
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
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
In iOS 11, you don’t have to. Just let the observer go out of scope. There is no penalty any longer for letting an observer die before the observed or for letting the observed die before the observer, so you have no actual work to do. On the other hand, if you really want to … Read more
Select the target, goto Build Settings > Swift Language Version: