Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Hey all, I know I'm having really tough questions lately, which nobody wants to or can answer to. But here I am again.

I'm having an ?global function? but I wanna make an call to an normal void function.

Code:
void MyCallBack (CFNotificationCenterRef center,
                 void *observer,
                 CFStringRef name,
                 const void *object,
                 CFDictionaryRef userInfo) {
}

In here I wanna call.. lets say:
Code:
[self myCallBack: name theObject:object theUserinfo:userInfo];
But it tells me self is undeclared.. Which I do understand, but I dont understand how to do it instead..
 
I'm having an ?global function? but I wanna make an call to an normal void function.

I think it would help us if you explained why you want to do this. What is the problem with the "global function" now and how do you think making it a "normal function" (by which I'm guessing you mean: a method of an object) will fix that?
 
Hey all, I know I'm having really tough questions lately, which nobody wants to or can answer to. But here I am again.

I'm having an ?global function? but I wanna make an call to an normal void function.

Code:
void MyCallBack (CFNotificationCenterRef center,
                 void *observer,
                 CFStringRef name,
                 const void *object,
                 CFDictionaryRef userInfo) {
}

In here I wanna call.. lets say:
Code:
[self myCallBack: name theObject:object theUserinfo:userInfo];
But it tells me self is undeclared.. Which I do understand, but I dont understand how to do it instead..

Your problem has nothing to do with it being a "global" function. Your problem is you're trying to use self in a function. Self is only defined within methods, not functions.

In the past I have set up pointers to self inside of my init method which are visible to the C functions. A singleton as suggested by KarlJay may be a better solution.
 
If you want to send a message to an object (say "self") from a function, you have to pass a reference to the object to that function, or put the object reference some place where it can be easily found (in the app delegate or other singleton, for instance).
 
My excuse for such late reply, and the unclear question.

Actually it shouldn't really be needed to call an an method from this function.
I would like to log the events into an textview of the current viewcontroller, which shudnt be needed in an textview but I killed my xCode partially:
- I have to fill in my admin username and password everything with building, running and at archiving almost an 8 times.
- When running an app directly on an device, it will crash out and xcode comes with an error. But the app is already on the device and works without problems if xCode is not listening to any NSLogs.

I'm not really sure how to work with the singletons.
I dont really understand to work of it.
 
I haven't worked with singletons, but IIRC, it's basically like a global space. An area where everything in the app can see it.

It sounds like you could use a function that logs output to a text window. You could write a simple function that is controlled by a #define and will control the direction of the log.

Depending on how many classes you have, you could write a method in the base of the class and use that to log to a window.

However, it really sounds like you need to fix Xcode. Maybe backup all the code and reinstall.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.