How to pass values by reference in objective C (iphone)

后端 未结 6 857
长发绾君心
长发绾君心 2020-12-02 09:03

I have a very basic question. I\'m a new iPhone programmer. My question is can anybody tell me how can I pass values by reference to a function in obj. C? I know how to do

6条回答
  •  我在风中等你
    2020-12-02 09:28

    There is no passing by reference (in C++ sense) in Objective C. You can pass your objects by pointer, and for primitive types by value.

    Example:

    void func(NSString* string)
    {
      ...
    }
    
    void func(NSInteger myint)
    {
     ...
    }
    
    ..
    NSString* str = @"whatever";
    NSInteger num = 5;
    
    func(str);
    func(num); 
    

提交回复
热议问题