I have been trying to initialise a Codable
struct using storyboard on the ViewController but it doesn't work.
Any idea on how to fix this issue?
Thanks in advance.
Here's what I tried on View Controller:
var images: ImageRequest
init(images: ImageRequest)
{
self.images = images
}
Code error above:
Error: 'required' initializer 'init(coder:)' must be provided by subclass of 'UIViewController'
init(images: ImageRequest)
{
self.images = images
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Code error above:
'super.init' isn't called on all paths before returning from initializer
init(images: ImageRequest)
{
self.images = images
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
The code above crashes. Error message:
Thread 1: Fatal error: init(coder:) has not been implemented
Here's what I tried on the Struct:
public struct ImageRequest: Codable {
public var albumId: Int
public var id: Int
public var title: String
public var url: URL
public var thumbnailUrl: URL
public init( albumId: Int, id: Int, title: String, url: URL, thumbnailUrl: URL) {
self.albumId = 0
self.id = 0
self.title = ""
self.url = URL(string: "")!
self.thumbnailUrl = URL(string: "")!
}
}
public struct ImageRequest: Codable {
public var albumId: Int
public var id: Int
public var title: String
public var url: URL
public var thumbnailUrl: URL
public init( albumId: Int, id: Int, title: String, url: URL, thumbnailUrl: URL) {
self.albumId = albumId
self.id = id
self.title = title
self.url = url
self.thumbnailUrl = thumbnailUrl
}
}