1 / 8

Programming Basics

Programming Basics. In Objective-C. Data Types. Data types that can be changed are called variables, types that cannot be changed are called constants. Basic data types like char, int , and float carry over from the C language.

taylor
Download Presentation

Programming Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Basics In Objective-C

  2. Data Types • Data types that can be changed are called variables, types that cannot be changed are called constants. • Basic data types like char, int, and float carry over from the C language. • Derivative data types like short, long, long long, and double are based on the basic types. • Objective-C defines BOOL, id, NSString and some others.

  3. Operators • Operators perform actions on data types. • Arithmetical operators are add (+), subtract (-), multiply (*), divide (/), and modulus (%). • Relational operators compare values of types. • > >= == != <= < • Logical operators represent AND(&&), OR(||), and NOT(!).

  4. Classes and Objects • A class is like a blueprint for a house, an object is like the house itself. • Classes you write will have an interface file (.h) and an implementation file (.m) • The interface file “prototypes” the implementation file • The implementation file contains the method definitions. • The naming convention for classes is to capitalize the first letter of each word with no spaces. • Example: MyClass.m

  5. Inheritance • You can build classes based on other classes. • The new class will have all of the abilities of its parent, or super class. • Most classes have the NSObject class somewhere in their ancestry. • Super class methods can be overridden by defining a method of the same name in the new class. • Super class methods do not have to be redefined in the new class.

  6. Encapsulation • Variables defined in Classes, Methods, and even if statements can be influenced or seen only by that section and its subsections. • One benefit to this is that you don’t have to come up with a unique name for every variable in your program. • Variables can be made global, but this is usually avoidable and considered bad practice.

  7. Methods • Methods define what objects of their class can do. • Methods can be either (-)instance or (+)class methods. • Methods can return a data type or not. (int) or (void) • Method names are usually written in camelCase. • Methods can take parameters, or not.

  8. Comments • Well commented code is helpful when trying to understand the code. Even the author might forget what they were thinking when they wrote the code and wish they had commented it better. • // begins a single-line comment • /* begins a multiple line comment. At the end of the last line will be a closing */ • Do you have any comments or questions?

More Related