Wednesday 22 April 2015

Py: Xcode: Add ARC disable flag to multiple files in Xcode project

I'm assume that Cocos2d files need to be ARC disables and each file is start with CC. Then If you have hundreds of files and you want to add ARC disable flag to each file, then my method could help you in quick way. Thanks for reading.
Beware Please take backup of your project before running this script.

Monday 20 April 2015

Set UIImage by setting color name

#define UIColorFromRGBHex(rgbValue) \
  [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
                  green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
                   blue:((float)(rgbValue & 0xFF))/255.0 \
                  alpha:1.0]


#define UIColorFromRGB(nRed,nGreen,nBlue) \
  [UIColor colorWithRed:(nRed)/255.0 \
                  green:(nGreen)/255.0 \
                   blue:(nBlue)/255.0 \
                  alpha:1.0]

@interface UIImage (imageWithColor)

+ (UIImage *)imageWithColor:(UIColor *)color;

@end


@implementation UIImage (imageWithColor)

+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end


[imageView setImage:[UIImage imageWithColor:UIColorFromRGB(255,0,0)]];

Thursday 16 April 2015

What is Error *error, Error **error and &error?

Let us consider below code, here we are passing a NSString pointer to pointer object. Which is same as call by reference in C language. But in Objective C we are taking every Object as reference type so taking pointer of an pointer object we need to write it as NSString **, not like NSString *.

In simple word if you understand the below code as Call by reference and call by value concept in Objective C. You can easily find out that why most of the methods are defined as Error **error instead of Error *error. We all know that In C and Objective C method can return only single value as return type. So put value in Error we need a pointer of Error.
Therefore in Objective C we passing Error ** as &error. It is all syntactical thing related to Objective C. Concept is the same as C language calling by reference and value.
Voila for reading this

-(void)changePointerOfString:(NSString **)strVal {
        *strVal = @"New Value";
}

-(void)changeOfString:(NSString *)strVal {
        strVal = @"New Value";
}


-(void)caller {
        NSString *myStr = @"Old Value";
        // myStr has value 'Old Value'
        NSLog(@"%@", myStr);

       [self changeOfString:myStr];
       // myStr has value 'Old Value'
       NSLog(@"%@", myStr);
       
       [self changePointerOfString:&myStr];
       // myStr has value 'New Value'
       NSLog(@"%@", myStr);
}

Sunday 12 April 2015

Ultra sonic distance test on raspberry pi

Our Motive to test ultra sonic waves, when object detect blink a led to show. Print the distance of object.  I have added a LED to show up the power is ON, one LED is check for pulse checking, and last LED will blink when object will detect. Object detection distance is set to 75 cm (.75m).