How to pass pointer to a reference as an argument to a function-Objective C

前端 未结 2 1964
北海茫月
北海茫月 2021-01-24 13:17

In C++ we will pass the pointer to a function as

bool getData(REMOTE_ID msId,RsEvent*& pEvent);

How to declare this in Objective C?

<
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 13:41

    You need to use pointers to simulate reference in C (and Objective-C):

    -(BOOL)getData:(REMOTE_ID)msId withEvent:(RsEvent**)pEvent {
       // do stuff with msId and *pEvent
    }
    

    and pass in the argument as a pointer:

    RsEvent* event;
    BOOl res = [foo getData:msId withEvent:&event];
    ...
    

提交回复
热议问题