Error Handling for Widget APIs in iOS that neither raise any exception nor return any value?

I was looking out for the error handling for rendering the Widgets(like UIButton, UIVIew etc) on the screen in iOS. I am painting the screen programmatically using swift.

Considering a simple Widget(like for say UIButton) when we try to create using its initializer and set some properties like 'setTitle' . These functions neither return any value upon success/failure nor in documentation they have mentioned about any exceptions which would be raised upon failure.

https://developer.apple.com/documentation/uikit/uibutton/settitle(_:for:)

So, how to do error handling here in this scenarios, in case the apis fail to due some reason, like memory issue? There must be some scenarios for these api failure.

I was under the impression that UIKit elements weren't supported for widgets.

Hi,

You can't use UIKit buttons in a Widget, but you can use SwiftUI buttons that take an Intent for a parameter which will allow you to have interaction on your Home Screen. They are designed to be lightweight, hence why UIKit is not explicitly supported. The SwiftUI views are archived into a timeline that is called based on the entry dates.

Hopefully this helps.

Rico


WWDR | DTS | Software Engineer

Error Handling for Widget APIs in iOS that neither raise any exception nor return any value?
 
 
Q