1/130
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Objective-C
General-purpose programming language built on C with Smalltalk features, making it object-oriented
Objective-C Primary Use
Used for developing iOS and Mac OS X operating systems and applications
Objective-C Origin
Developed by NeXT for NeXTSTEP OS and later adopted by Apple
Objective-C Example Code
Basic program using #import, main, and NSLog to print output
Foundation Framework
Provides extended data types like NSArray, NSDictionary, NSSet and utilities for files, strings, URLs, dates, and error handling
Purpose of Learning Objective-C
To become better at designing, implementing, and maintaining systems
Objective-C Advantage
Large iOS user base and growing Mac OS X ecosystem
Try It Option Online
Allows compiling and executing Objective-C code without local setup
Local Environment Setup
Requires a text editor and GCC compiler
Text Editor
Tool for writing code (e.g., Notepad, vim, EMACS)
Source File
File containing code, usually with .m extension
GCC Compiler
Converts human-readable code into machine-executable program
Objective-C Program Structure
Consists of preprocessor commands, interface, implementation, methods, variables, statements, and comments
Preprocessor Command
#import used to include header files before compilation
Interface
Defines class structure and methods using @interface
Implementation
Defines method behavior using @implementation
Method Declaration
Defined using - (returnType)methodName;
NSObject
Base class of all Objective-C objects
Main Function
Entry point of program execution (int main())
NSLog
Function used to print output to console
Return 0
Terminates program successfully
Comments
Ignored by compiler, written using / /
Objective-C Tokens
Smallest elements of a program (keywords, identifiers, constants, strings, symbols)
Example Tokens
NSLog, @, (, "Hello, World!", )
Semicolon (;)
Terminates statements
Comments Rule
Cannot be nested and not allowed inside strings
Identifier
Name for variables, functions, etc.
Identifier Rules
Must start with letter or underscore, followed by letters/digits/underscores
Invalid Identifier Characters
@, $, %
Case Sensitivity
Manpower and manpower are different
Valid Identifiers
mohd, zara, abc, move_name, a_123, myname50, _temp, j, a23b9, retVal
Objective-C Data Types
System for declaring variables/functions that defines storage size and data interpretation
Basic Types
Arithmetic types including integer and floating-point types
Enumerated Types
Define variables with specific discrete integer values
Void Type
Indicates no value
Derived Types
Includes pointers, arrays, structures, unions, and functions
Aggregate Types
Arrays and structures
Variable
Named storage location used to store data
Variable Type Role
Determines memory size, value range, and operations
Variable Naming Rules
Letters, digits, underscore; must start with letter or underscore
Case Sensitivity (Variables)
Uppercase and lowercase are different
char
Single byte integer
int
Natural integer size of machine
float
Single precision floating-point
double
Double precision floating-point
void
No type
Variable Definition
Specifies type and allocates storage
Syntax (Definition)
type variable_list;
Example Definition
int i, j, k;
Variable Initialization
Assigning value during declaration
Example Initialization
int d = 3, f = 5;
Variable Declaration
Tells compiler variable exists without allocating memory
extern Keyword
Used to declare variables defined elsewhere
Rule
Variable can be declared many times but defined once
Lvalue
Expression that can appear on left or right side of assignment
Rvalue
Expression that can only appear on right side
Valid Example
int g = 20;
Invalid Example
10 = 20;
Constants
Fixed values that cannot change during execution
Literal
Another term for constant values
Integer Literal
Whole number constants (decimal, octal, hexadecimal)
Decimal Literal
No prefix
Octal Literal
Prefix 0
Hexadecimal Literal
Prefix 0x or 0X
Integer Literal Suffix
U (unsigned), L (long)
Valid Integer Literal
212, 215u, 0xFeeL
Invalid Integer Literal
078, 032UU
Floating Literal
Numbers with decimal/exponent
Valid Floating Literal
3.14159, 314159E-5L
Invalid Floating Literal
510E, 210f, .e55
Character Literal
Single character in single quotes
Escape Sequence
Special characters with backslash
\
Backslash
'
Single quote
"
Double quote
?
Question mark
\a
Alert/bell
\b
Backspace
\f
Form feed
\n
Newline
\r
Carriage return
\t
Horizontal tab
\v
Vertical tab
\ooo
Octal value
\xhh
Hexadecimal value
String Literal
Characters inside double quotes
String Concatenation
Adjacent strings combine automatically
#define
Preprocessor used to define constants
const Keyword
Declares typed constant
Best Practice
Constants should be in uppercase
Operator
Symbol that performs mathematical or logical operations
Types of Operators
Arithmetic, Relational, Logical, Bitwise, Assignment, Misc
+
Adds two operands (A + B = 30)
-
Subtracts second operand from first (A - B = -10)
*
Multiplies operands (A * B = 200)
/
Divides numerator by denominator (B / A = 2)
%
Modulus, returns remainder (B % A = 0)
++
Increment by 1 (A++ = 11)
--
Decrement by 1 (A-- = 9)
==
True if equal (A == B is false)