Objective C Tutorial (Programing Language)
By: Luis A. Sierra
- Encapsulation
- Data hiding
- Inheritance
- Polymorphism
Foundation Framework
Foundation Framework provides large set of features and they are listed below.
- It includes a list of extended datatypes like NSArray, NSDictionary, NSSet and so on.
- It consists of a rich set of functions manipulating files, strings, etc.
- It provides features for URL handling, utilities like date formatting, data handling, error handling, etc.
XCode is Apple’s IDE that developers can use to build codes for iPhones, iPad and other device-based applications. You can use the IDE to develop code using Swift programming language. It also extends support for multiple programming languages, which makes it the most superior programming language.
This intelligent integrated development environment was created to support Objective-C and Swift programming languages. It comes with modern libraries and support for modernized coding that enables swift solutions.
This is one of the best and most popular Swift IDEs you can use to build iOS applications. CodeRunner is devised only for iOS, so it doesn’t extend cross-platform support.
This is an intelligent and cross-platform IDE developed by JetBrains to help program applications using Swift language. It does offer a debugger and a powerful editor that helps build the code. You can use several analysis tools for the best outcomes and quick coding decisions.
To get started using Simulators:
Install Xcode from the Mac App Store.
Once installed, launch Xcode so that it can complete its first launch.
A dialog will be presented that indicates which Simulator runtimes are built-in, and which Simulator runtimes you may download. For now, choose Continue to finish setting up Xcode.
Hello World application
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
printf("Hello, World! \n");
return 0;
}
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
printf("Hello, World! \n");
return 0;
}
// This is a comment printf("Welcome to http://interesting-homemade-projects \n");
Multi-line comments start with /* and ends with */.
/* The code below will print the url of my web site to the screen */
printf("Welcome to http://interesting-homemade-projects \n");
Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of an equal sign followed by a constant expression as follows
data type name;
Example:
int Thousand = 1000;
float Pi = 3.14;
NSString *AuthorName = @"Luis A. Sierra";
Example 2: Mixed With C/C++
int Thousand = 1000;
float Pi = 3.14;
char AuthorName[] = "Luis A. Sierra"; // C/C++ String
Now you can see with your own eyes that the theory described above is possible. If you know C/C++, you can program in Objective-C on your own.
If you want to learn C/C++ you can see my other tutorial about C/C++:
https://interesting-homemade-projects.blogspot.com/2024/02/tutorial-cc-part-1.html
Case sensitivity defines whether uppercase and lowercase letters are treated as distinct or equivalent.
int Thousand = 1000;
float Pi = 3.14;
NSString *AuthorName = @"Luis A. Sierra";
Example 2: Mixed With C/C++
int Thousand = 1000;
float Pi = 3.14;
char AuthorName[] = "Luis A. Sierra"; // C/C++ String
Now you can see with your own eyes that the theory described above is possible. If you know C/C++, you can program in Objective-C on your own.
https://interesting-homemade-projects.blogspot.com/2024/02/tutorial-cc-part-1.html
"Objective-C : is case sensitive"
The following table shows the available data types in Objective-C programming language with memory size and range of values.
int id = 10;
double percentage = 18.55;
char gender = 'M';
BOOL isVerified = YES;
NSString *name = @"Luis A. Sierra";
printf("Id: %d\n", id);
printf("Name: %s\n", [name UTF8String]);
printf("Percentage: %.2f\n", percentage);
printf("Gender: %c\n", gender);
printf("Verified: %s\n", isVerified ? "true" : "false");
Is the process of converting one data type to another. The type conversion is only performed to those data types where conversion is possible.
Example:
int num = 10;
double dec = 5.25;
BOOL boolean = YES;
// Convert to String
printf("%s\n", [[NSString stringWithFormat:@"%d", num] UTF8String]);
// Convert to Double
double convertedToDouble = (double)num;
printf("%f\n", convertedToDouble);
// Convert to Int
int convertedToInt = (int)dec;
printf("%d\n", convertedToInt);
// Convert to String
const char *strBool = boolean ? "true" : "false";
printf("%s\n", strBool);
MORE EXAMPLES:
* Convert to Integer
* Convert to Double
* Convert to Boolean
* Convert to Date
* Convert to Time
* Format DateTime
* DayName of DateTime
* Convert to ASCII
* String Replace
* String Length
An array is a data structure consisting of a collection of elements, of same memory size, each identified by at least one array index or key. An array is stored such that the position of each element can be computed from its index.
Array Length / Size
In Objective-C different types of operators are available; those are:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Misc Operators
Arithmetic Operators
Arithmetic operators are used to perform common mathematical operations.
Relational operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions
Logical Operators
Logical operators are used to determine the logic between variables or values:
Bitwise Operators
bitwise operators are used to perform operations directly on the binary representations of numbers.
Assignment Operators
Assignment operators are used to assign values to variables.
Misc Operators
misc operator is miscellaneous operator, are few other important operators including sizeof and ? : supported by Objective-C Language.
The if-else statement is used to execute both the true part and the false part of a given condition. If the condition is true, the if block code is executed and if the condition is false, the else block code is executed
The CASE expression goes through conditions and returns a value when the first condition is met (like an if-then-else statement)
The for statement, also called the for loop, lets you repeat a statement or compound statement a specified number of times.
Example - Up:Example - Down:
A do while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
A method in object-oriented programming (OOP) is a procedure associated with an object, and generally also a message. An object consists of state data and behavior; these compose an interface, which specifies how the object may be used. A method is a behavior of an object parametrized by a user.
Note: Methods do not return value.
A function, subprogram, procedure, method, routine or subroutine is a callable unit that has a well-defined behavior and can be invoked by other software units to exhibit that behavior.
Note: functions return a value.
A class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).
Methods and functions are declared differently within a class, this is due to the design of the Objective C language.
Objects are a programming paradigm based on the concept of objects, which can contain data and code: data in the form of fields (often known as attributes or properties), and code in the form of procedures (often known as methods). In OOP, computer programs are designed by making them out of objects that interact with one another.
In class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of function called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.

The meaning of Encapsulation, is to make sure that "sensitive" data is hidden from users. To achieve this, you must declare class variables/attributes as private (cannot be accessed from outside the class). If you want others to read or modify the value of a private member, you can provide public get and set methods.
Inheritance is one of the core features of object-oriented programming. It's a programming procedure that allows you to reuse code by referencing the behaviors and data of an object. In other words, a class that inherits from another class shares all the attributes and methods of the referenced class.
Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance.
Exception is typically used to denote a data structure storing information about an exceptional condition. One mechanism to transfer control, or raise an exception, is known as a throw; the exception is said to be thrown. Execution is transferred to a catch.
int id = 10;
double percentage = 18.55;
char gender = 'M';
BOOL isVerified = YES;
NSString *name = @"Luis A. Sierra";
printf("Id: %d\n", id);
printf("Name: %s\n", [name UTF8String]);
printf("Percentage: %.2f\n", percentage);
printf("Gender: %c\n", gender);
printf("Verified: %s\n", isVerified ? "true" : "false");
int num = 10;
double dec = 5.25;
BOOL boolean = YES;
// Convert to String
printf("%s\n", [[NSString stringWithFormat:@"%d", num] UTF8String]);
// Convert to Double
double convertedToDouble = (double)num;
printf("%f\n", convertedToDouble);
// Convert to Int
int convertedToInt = (int)dec;
printf("%d\n", convertedToInt);
// Convert to String
const char *strBool = boolean ? "true" : "false";
printf("%s\n", strBool);
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Misc Operators
Arithmetic operators are used to perform common mathematical operations.
Logical operators are used to determine the logic between variables or values:
bitwise operators are used to perform operations directly on the binary representations of numbers.
Assignment Operators
Assignment operators are used to assign values to variables.
The CASE expression goes through conditions and returns a value when the first condition is met (like an if-then-else statement)
The for statement, also called the for loop, lets you repeat a statement or compound statement a specified number of times.
Example - Up:
Note: functions return a value.
A class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).
In class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of function called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.








Post a Comment