Recall that a delegate is required if you want other classes to respond to your Screenlet’s actions. Create your delegate by following the first step in the tutorial on adding a Screenlet delegate. A list Screenlet’s delegate must also define a method for responding to a list item selection. For example, Bookmark List Screenlet’s delegate needs the following methods:
screenlet(_:onBookmarkListResponse:)
: Returns theBookmark
results when the server call succeeds.screenlet(_:onBookmarkListError:)
: Returns theNSError
object when the server call fails.screenlet(_:onBookmarkSelected:)
: Returns theBookmark
when a user selects it in the list.
The BookmarkListScreenletDelegate
protocol defines these methods:
@objc public protocol BookmarkListScreenletDelegate : BaseScreenletDelegate {
optional func screenlet(screenlet: BookmarkListScreenlet,
onBookmarkListResponse bookmarks: [Bookmark])
optional func screenlet(screenlet: BookmarkListScreenlet,
onBookmarkListError error: NSError)
optional func screenlet(screenlet: BookmarkListScreenlet,
onBookmarkSelected bookmark: Bookmark)
}
Nice work! Next, you’ll create the Screenlet class.