How to add an observer to NSNotificationCenter in a C++ class using Objective-C++?

前端 未结 3 1952
一整个雨季
一整个雨季 2021-01-05 08:08

I have a C++ class that I recently renamed from *.cpp to *.mm to support objective-c. So I can add the following objective-c code.

[[NSNotificationCenter defa         


        
3条回答
  •  孤城傲影
    2021-01-05 08:45

    Or you could also just use blocks and do:

    [
        [NSNotificationCenter defaultCenter] addObserverForName: @"notify"
        object: nil
        queue: nil
        usingBlock: ^ (NSNotification * note) {
            // do stuff here, like calling a C++ method
        }
    ];
    

提交回复
热议问题