Objective-C was invented by Brad Cox and Tom Love. It adds object-oriented programming to the C programming language and is used for Apple's operating systems. Objective-C source files have a .m extension and interface files have a .h extension. Objective-C derives its object syntax from Smalltalk and messages are enclosed in square brackets. It allows dynamic typing using the "id" keyword.
Contents :
Language Concepts
How Objective C works- Basics
Data Types
NSInteger
NSNumber
Operators
Loop
Inheritance
Method Overloading
Mutable and Immutable Strings
Mutable and Immutable Arrays
File Management
Contents :
Language Concepts
How Objective C works- Basics
Data Types
NSInteger
NSNumber
Operators
Loop
Inheritance
Method Overloading
Mutable and Immutable Strings
Mutable and Immutable Arrays
File Management
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Chris Richardson
Higher-order functions such as map(), flatmap(), filter() and reduce() have their origins in mathematics and ancient functional programming languages such as Lisp. But today they have entered the mainstream and are available in languages such as JavaScript, Scala and Java 8. They are well on their way to becoming an essential part of every developer’s toolbox.
In this talk you will learn how these and other higher-order functions enable you to write simple, expressive and concise code that solve problems in a diverse set of domains. We will describe how you use them to process collections in Java and Scala. You will learn how functional Futures and Rx (Reactive Extensions) Observables simplify concurrent code. We will even talk about how to write big data applications in a functional style using libraries such as Scalding.
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Chris Richardson
Higher-order functions such as map(), flatmap(), filter() and reduce() have their origins in mathematics and ancient functional programming languages such as Lisp. But today they have entered the mainstream and are available in languages such as JavaScript, Scala and Java 8. They are well on their way to becoming an essential part of every developer’s toolbox.
In this talk you will learn how these and other higher-order functions enable you to write simple, expressive and concise code that solve problems in a diverse set of domains. We will describe how you use them to process collections in Java and Scala. You will learn how functional Futures and Rx (Reactive Extensions) Observables simplify concurrent code. We will even talk about how to write big data applications in a functional style using libraries such as Scalding.
My talk at BarCamp London 5: An introduction to Cocoa development and how web developers can cheat.
Source code to go with this presentation is available here: http://georgebrock.com/conferences/barcamplondon5
Slides from my "Swift, Swiftly" session at Øredev 2014.
Revealed by Apple in June of this year, the Swift programming language has already established itself as a huge leap forward for iOS and OS X developers. Learn the ins and outs of this new language, see how it compares to other modern OO languages, and hear about how Apple developers are using Swift to achieve new levels of productivity and efficiency.
Full video available: http://oredev.org/2014/sessions/swift-swiftly
The PPTs from one of the event of iWillStudy.com - a leading start-up in the education space in India. This PPT is being used at an event where they taught iPhone programming and applications development.
Programs are complete in best of my knowledge with zero compilation error in IDE Bloodshed Dev-C++. These can be easily portable to any versions of Visual Studio or Qt. If you need any guidance please let me know via comments and Always Enjoy Programming.
2. INTRODUCTION
Objective-C was invented by Brad Cox and Tom Love.
Objective-C is a high-level, object-oriented programming language that
adds Smalltalk-style messaging to the C programming language
It is the main programming language used by Apple for the OS X
and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch
Mayank Jalotra
3. INTRODUCTION (Cont.)
Objective-C source files has a “.m” extension.
“.h” file is the interface file.
For example:
─ main.m
─ List.h (Interface of List class.)
─ List.m (Implementation of List class.)
Mayank Jalotra
4. SYNTAX
Objective-C is a thin layer on top of C, and moreover is
a strict superset of C.
It is possible to compile any C program with an Objective-C
compiler.
Objective-C derives its object syntax from Smalltalk.
All of the syntax for non-object-oriented operations are identical to
that of C
Mayank Jalotra
5. Basic syntax structure
C++ syntax :
void function(int x, int y, char z);
Object.function(x, y, z);
Objective-C syntax :
-(void) function:(int)x, (int)y, (char)z;
[Object function:x, y, z];
Mayank Jalotra
6. Keyword: id
The word „id‟ indicates an identifier for an object
much like a pointer in c++.
This uses dynamic typing.
For example, if Pen is a class…
extern id Pen;
id myPen;
myPen = [Pen new ]; Mayank Jalotra
7. MESSAGES
To get an object to do something, you send it a message
telling it to apply a method. In Objective-C, message
expressions are enclosed in square brackets
[receiver message].
In Objective-C one does not simply call a method;
one sends a message
Mayank Jalotra
8. Messages Cont.
For example, this message tells the myRect object
to perform its display method, which causes the
rectangle to display itself
[myRect display];
[myRect setOrigin:30.0:50.0];
Mayank Jalotra
10. CODE EXPLAINATION [1]
CODE EXPLAINATION
The parameter argc is the argument count at the time the
program is invoked. For example, if your program was called
“justarty” and you typed “justarty one two” into the command line
the computer would execute justarty.exe after passing “one” and
“two” into the program.
The value stored in the program for argc would be 3 (including
the program name). The parameter argv on the other hand is the
actual array of arguments. In our example the array of arguments
would be
argv[0] = “justarty”
argv[1] = “one”
argv[2] = “two”
Mayank Jalotra
11. CODE EXPLANATION [2]
NSAutoreleasePool * pool = [[NSAutoreleasePool
alloc] init];
• The NSAutoreleasePool is one of Cocoa's memory-
management tools.
NSLog(@"Hello, World!");
The NSLog function works very much like printf in the C
language. The difference is that NSLog takes an NSString
object instead of a C string. The @" . . . " construct is a
compiler directive that creates an NSString object using
the characters between the quotation marks.
Mayank Jalotra
12. CODE EXPLANATION [3]
[pool release];
• This line contains another part of Cocoa's memory
housekeeping
return 0;
• A return from the main function indicating a normal program
exit
//NS stands for NeXTSTEP. All of the classes and functions in the Cocoa
frameworks start with NS.
Mayank Jalotra
13. Example 1:
#import <Foundation/Foundation.h>
int main(int argc, const char* argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSLog (@”Hello World”);
int undergrads = 120;
int postgrads = 50;
int students = undergrads + postgrads;
NSLog (@”Now featuring...n %i Computer Science students”, students);
[pool drain];
return 0;
}
Mayank Jalotra
14. INTERFACE
The declaration of a class interface begins with the compiler
directive @interface and ends with the directive @end.
@interface ClassName : ItsSuperclass
{
instance variable declarations
}
method declarations
@end
─ Goes in source(.h) file
Mayank Jalotra
15. IMPLEMENTATION
The implementation of the class is done as :
#import <Foundation/Foundation.h>
#include “interfacename.h“
@implementation ClassName
define method function here;
define another method function here;
define yet another method function here;
@end
─ Goes in source(.m) file
Mayank Jalotra
16. Example 2: ComputerScience.h
Example 3: ComputerScience.h
@interface ComputerScience : NSObject
{
int mUndergrads;
int mPostgrads;
}
-(void) print;
-(void) setUndergrads: (int) undergrads;
-(void) setPostgrads: (int) postgrads;
@end
Mayank Jalotra
18. Data Structures
Objective-C arrays are similar to C arrays, but you can initialize whole
array in a list.
Or just a few indices of the array. The rest are set to 0.
Or mix and match; the example will create an array of size [8].
int values[3] = { 3, 4, 2 };
char letters[3] = { 'a', 'c', 'x' };
float grades[100] = {10.0,11.2,1.1};
int array[] = {[3]=11,[2]=1,[7]=0};
Mayank Jalotra
19. Arrays and Functions
Arrays can be passed as arguments to functions.
This function will print every integer in an array but it needs to also be
told how long the array is (arrayLength).
Statements with hard-coded indices such as array[4] are potentially
dangerous.
void function(int array[], int arrayLength) {
int fourthValue = array[4];
for (int i = 0; i < arrayLength; i++) {
NSLog(@”%i”, array[i]; }
}
Mayank Jalotra
20. References
Learning Cocoa with Objective-C By Apple Computer, Inc. , James
Duncan Davidson
Start Programming the Mac Using Objective-C By Bert
Altenberg, Alex Clarke
Objective-C for Absolute Beginners By Gary Bennett, Mitch Fisher, Brad
Lees
Various Authors. Wikipedia: the Free Encyclopedia
http://en.wikipedia.org
http://stackoverflow.com/questions
Mayank Jalotra