Best place to start iOS app development. Here we combine multiple sources to make iOS development simple and easy way.
Wednesday, 27 November 2013
Monday, 25 November 2013
To:Mayank Purwar |
Block??
Blocks are “anonymous functions” and can be defined inline.
Blocks capture read-only copies (unless defined with __block, more on that later) of local variables, similar to “closures” in other languages.
Blocks capture read-only copies (unless defined with __block, more on that later) of local variables, similar to “closures” in other languages.
Block variable
• To define a block variable, the ^ operator is used.
• BOOL ( ^isInputEven)(int) = ^(int input) {
if(input % 2 == 0) return YES;
else
return NO;
check image**
• Call to a block is similar to c function call int x = -101;
NSLog(@"%d %@ number", x, isInputEven(x) ? @"is an even" : @"is not an even");
Output is:
-101 is not an even number
• BOOL ( ^isInputEven)(int) = ^(int input) {
if(input % 2 == 0) return YES;
else
return NO;
check image**
• Call to a block is similar to c function call int x = -101;
NSLog(@"%d %@ number", x, isInputEven(x) ? @"is an even" : @"is not an even");
Output is:
-101 is not an even number
Blocks and variable scope
float price = 1.99;
float (^finalPrice)(int) = ^(int quantity) {
// Notice local variable price is accessible in the block
return quantity * price; };
• thecodeinthebodyreferencesthevariable ‘price’ which is defined outside the block.
• The output for the log statement is: Ordering 10 units, final price is: $19.90
• Now change the price and run the program price = .99;
NSLog(@"Ordering %d units, final price is: $%2.2f", orderQuantity, finalPrice(orderQuantity));
• The output for the block, with the price variable updated is:
Ordering 10 units, final price is: $19.90
float (^finalPrice)(int) = ^(int quantity) {
// Notice local variable price is accessible in the block
return quantity * price; };
• thecodeinthebodyreferencesthevariable ‘price’ which is defined outside the block.
• The output for the log statement is: Ordering 10 units, final price is: $19.90
• Now change the price and run the program price = .99;
NSLog(@"Ordering %d units, final price is: $%2.2f", orderQuantity, finalPrice(orderQuantity));
• The output for the block, with the price variable updated is:
Ordering 10 units, final price is: $19.90
Using ___block Storage Modifier
• To allow a variable defined outside a block to be mutable, apply the ___block storage type modifier:
___block float price = 1.99;
float (^finalPrice)(int) = ^(int quantity) {
return quantity * price; };
int orderQuantity = 10; price = .99;
• The output for the block, with the price variable updated is:
• With block storage modifier – Ordering 10 units, final price is: $9.90
___block float price = 1.99;
float (^finalPrice)(int) = ^(int quantity) {
return quantity * price; };
int orderQuantity = 10; price = .99;
• The output for the block, with the price variable updated is:
• With block storage modifier – Ordering 10 units, final price is: $9.90
Passing block as parameter
• Since blocks are “variables” you can pass blocks to methods and functions.
• -(NSArray*)each:(void(^)(id))block;
• - (NSArray *)each:(void (^)(id object))block {
for(id mObject in self) block(mObject); return self;
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSArray *array = [NSArray arrayWithObjects:@"Number one", @"Number two", nil];
[array each:^(id object) { NSLog(object);
}];
More details :Apple Docs
• -(NSArray*)each:(void(^)(id))block;
• - (NSArray *)each:(void (^)(id object))block {
for(id mObject in self) block(mObject); return self;
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSArray *array = [NSArray arrayWithObjects:@"Number one", @"Number two", nil];
[array each:^(id object) { NSLog(object);
}];
More details :Apple Docs
Sunday, 24 November 2013
Hi..
If you need any particular topic tutorial please mention those topics as a comment to this post.
So i can add that one also.
And the next tutorial's am going to submit is
Hopefully i will post it today night itself...
There are mainly 2 types
1. Using iOS In App Purchase
2.Using Google AdMobs
If you need any particular topic tutorial please mention those topics as a comment to this post.
So i can add that one also.
And the next tutorial's am going to submit is
"Earn money from your ios App's"
Hopefully i will post it today night itself...
There are mainly 2 types
1. Using iOS In App Purchase
2.Using Google AdMobs
Subscribe to:
Posts (Atom)