How do I call a function with float return type?

Discussion in 'iOS Programming' started by Jules2010, Apr 7, 2010.

  1. Jules2010 macrumors member

    Joined:
    Apr 7, 2010
    #1
    Heres my function which xcode likes.
    Code:
    - (float) getLength:(NSString *)str
    {
    	float ret = 0.0;
    	
    	return ret;
    }
    Heres the calls I've tried to that function
    Code:
    lbl.text = self.getLength:@"1";
    lbl.text = [NSString stringWithFormat:@"%i. ", self.getLength:@"1"];
    I've tried similar variations but xcode doesn't like it.

    I get this error.
    error: request for member 'getLength' in something not a structure or union

    Help!

    TIA
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    The . syntax can only be used for properties. You have defined a method (not a function) so have to make a call to a method.

    Code:
    [self getLength:@"1"];
    
    Also I do not expect that setting the text property of a label (which is a NSString) to a float would work.

    I suggest you need to stop writing code and sit down with the Objective-C Introduction and cup of coffee/tea/beer.
     
  3. Jules2010 thread starter macrumors member

    Joined:
    Apr 7, 2010
    #3
    Thanks.

    I have gone through a short study book course, but its been lacking in some areas, but your right I need to find the time to study further. Good link, wish I'd had that sooner.
     

Share This Page