I know what a function is, but I am trying to write a few into my project. I have just watched a video series on Objective-C from Lynda.com where I got the idea from.
In the video is it is explained that I can write a function like this:
void declareWebView ()
However if I write it like that into my code, the error comes up and says that my _webView and self (as self.view) are not available.
if I write it like this:
-(void) declareWebView
Then I do not have an issue.
Any ideas on how to get the first one right?
As far as I can tell, I cannot set any parameters with the second way of writing.
The first is as you said called a function. It is part of the C part of Objective-C, and is not connected to objects or classes, so the variable
selfor any instance variables of an object don’t have any meaning. You can pass it variables that are objects though like so:The second is a method, and in a method you can access self and, within instance methods, access instance variables. Replacing the “-” in front of the method with a “+” makes it a class method. In a class method you can’t access instance variables and
selfrefers to the class itself, not an instance.Hope this helps!