Full video game engine with 3D rendering and real-world physics in a browser? Yes. Ability to style <select> dropdowns in a browser? No.
Nicholas C. Zakas - @slicknet
Action methods vs Normal methods
So what is the difference between an action method and a regular method? Nothing. An action method is really just the same as any other method. The only special thing is the (IBAction)
specifier. This allows Interface Builder to see the method so you can hook it up to your buttons, sliders, and so on.
Other methods, such as viewDidLoad
, do not have the IBAction
specifier. This is a good thing because all kinds of mayhem would occur if you hooked them up to your buttons.
This is the simple form of an action method:
|
|
You can also ask for a reference to the object that triggered this action:
|
|
But this method cannot be used as an action from Interface Builder:
|
|
Properties v.s Instance Variables
Properties and instance variables have a lot in common. In fact, when you create a property, it is “backed” by an instance variable. That means your slider property stores its value in an instance variable named _slider (note the leading underscore). This instance variable was automatically added to the view controller by the Objective-C compiler.
Why? Well, a property needs to store its value somewhere and an instance variable is a good place for that. You can tell the difference between the two because properties are always accessed using self.
This uses the property:
|
|
This uses the backing instance variable directly:
|
|
So what is the added benefit of using a property over an instance variable? There are several reasons but mainly instance variables are supposed to be used only by the insides of an object. Other objects aren’t intended to see them or use them.
Properties, however, can be accessed by other objects that are outside of your view controller. You’ll learn much more about this in the next tutorials because “information hiding” is an important topic in object-oriented programming.
By the way, properties are not just for making outlets. It is customary to use properties for the outlets in your storyboard, but as you will see later, you can also make properties for things that are not in the storyboard.
Express - Setting view engine
view engine
holds the template file extension, e.g. ‘jade’ or ‘html’.
Omitting this variable will cause res.render
failed to load templates. Explicitly specify the extension if omitted this variable:
|
|
Express - Setting environment
env
variable is used to store the current environment node for this particular Node.js process.
The value is automatically set by Express.js from process.env.NODE_ENV, or development
if that value is not set.
The most common values for env
setting are:
- test
- stage
- preview
- production
We can argument the env
by:
|
|
However, the better way is to start the app in the CLI:
|
|