THe error you are seeing is very clear. If you don't understand it, I suggest you to read the docs for throwing functions here.
There are several ways to fix this issue, the thing is - why the heck would you mark initialiser for singleton object throwing... One thing you could do is to wrap up the initialiser into setupManager
function like this:
public class Manager {
static let shared = setupManager()
// throwable initialier
private init() throws {
}
static func setupManager() -> Manager {
do {
return try Manager()
} catch let error {
fatalError("error:\(error)")
}
}
}
In shorter declaration without the setup method:
public class Manager {
static var shared: Manager {
do {
return try Manager()
} catch let error {
// Immediatly stops program execution...
fatalError("An error occured: \(error)")
}
}
// throwable initialier
private init() throws {
}
}
The other way to solve this problem would be to use try? and make the shared instance optional (found in the documentation I posted above):
public class Manager {
static let shared: Manager? = try? Manager()
// throwable initialier
private init() throws {
}
}
Other way around this could be to force unwrap it, but that's not what you want to do since it's really bad approach to problems...
Please keep in mind that always when you code something, fix the core of the problem, not the symptoms, it can always get worse. I don't see any reason for making singleton initialiser throwing in any case, so if you are dependent on some code in the app which should be handed to it, rethink your architecture. Questions are welcome. Wish happy coding!