CreateObjcDelegateWithContext

Typehandler
DictionaryLCB
LibraryLiveCode Builder
Syntax
CreateObjcDelegateWithContext(<pProtocol>,<pHandlerMapping>,<pContext>)
Associationscom.livecode.objc
Summary

Create an Objective-C object with LCB implementations of methods of a protocol.

Parameters
NameTypeDescription
pProtocol

The name of the protocol

pHandlerMapping

A mapping from the protocol's selector names to LCB handlers

pContext

Any context required in the callback.

Example
handler NumberOfItemsInMenuCallback(in pContext as String, in pMenu as ObjcId) returns CLong
    -- pContext is the tag for this menu
    return the number of elements in mMenuArray[pContext]
end handler

public handler GetNSMenuDelegate(in pMenuTag as String) returns ObjcObject
    return CreateObjcDelegateWithContext("NSMenuDelegate", \
                                           { "numberOfItemsInMenu:": \
                                           NumberOfItemsInMenuCallback }, \
                                           pMenuTag)
end handler
Values
NameTypeDescription
return

An Objective-C object which calls the appropriate LCB handler on receiving any of the specified selectors.

RelatedHandler: CreateObjcDelegate, CreateObjcInformalDelegate, CreateObjcInformalDelegateWithContext
Description

Use the CreateObjcDelegateWithContext handler to create instances of Objective-C delegate classes with LCB implementations of protocol methods. Once created these can be set in the usual way on an instance of the appropriate class (by binding to -setDelegate:), typically so that callbacks triggered by user interaction with a widget can be handled in LCB.

If no context is required to be passed as a parameter to the callback, use CreateObjcDelegate.

Some protocols consist of purely optional methods. In this case the information about the protocol's methods are not available from the
objective-c runtime API. In this situation CreateObjcInformalDelegateWithContext should be used instead.