Global function -> normal function?

Discussion in 'iOS Programming' started by DennisBlah, Feb 27, 2014.

  1. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    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..
     
  2. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #2
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    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?
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    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.
     
  5. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #5
    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).
     
  6. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #6
    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.
     
  7. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #7
    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.
     

Share This Page