Skip to content

Instantly share code, notes, and snippets.

__block NSNumber *val = [NSNumber numberWithInt:0];
void (^blk)(void) = ^{
__block NSNumber *val1 = val;
void (^blk2)(void) = ^{
val1 = [NSNumber numberWithInt:1];
};
NSLog(@"val:%@ val1:%@", val, val1);
val = [NSNumber numberWithInt:2];
NSLog(@"val:%@ val1:%@", val, val1);
val1 = [NSNumber numberWithInt:3];
@cqa02303
cqa02303 / gist:1193858
Created September 5, 2011 01:28
dispatch_syncに絶望してこんな事をしている
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_async(queue, ^{
// hogehoge
// ここに処理を書く
//
dispatch_semaphore_signal(semaphore);
});
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_release(semaphore);
@cqa02303
cqa02303 / gist:633534
Created October 19, 2010 03:01
ついカッとなって勢いで書いた奴
- (NSString*)base64:(NSData*)fromData {
static unsigned char base64Table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const unsigned char *data = fromData.bytes;
char *buff = NSZoneMalloc(self.zone, fromData.length * 4 / 3 + 4);
int o = 0, i;
for (i = 0; i <= fromData.length; i++, o++) {
switch (i % 3) {
case 0:
if (i < fromData.length) {
buff[o] = base64Table[(data[i] >> 2) & 0x3f];
// アニメーションの開始側
// 予めanimationRemainに繰返し回数を入れておいてperformSelectorで呼びます
- (void)continueGadgetAnimating {
animationRemain --;
EasterEggView *image = [[[SnowGadget alloc] initWithImages:self.snowImages.subviews] autorelease];
[self.touchView addSubview:image];
[image startAnimating];
if (animationRemain > 0) {
[self performSelector:@selector(continueGadgetAnimating) withObject:nil afterDelay:0.6f];
}
#pragma mark -
#pragma mark animationScenario
// イメージを横長の領域に散らして配置したViewを作成する
- (id)initWithImages:(NSArray*)images {
if (self = [super init]) {
// Initialization code
NSLog(@"EasterEggImage initWithImage");
int randVal = 0;
UIImageView *timage = nil;
#pragma mark -
#pragma mark ButtonAction // ボタンの応答
// 写真ソース選択を出す
- (IBAction)pictAction:(id)sender {
NSLog(@"pictAction");
[((TakePhotoView*)self.view) finderCloseForceAction:self];
UIActionSheet *sheet = [UIActionSheet alloc];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
if (self.appDelegate.sourceImage == nil) {
sheet = [[sheet initWithTitle:@"Select a Photo Source" delegate:self cancelButtonTitle:@"CANCEL" destructiveButtonTitle:nil otherButtonTitles:@"Built in Camera", @"Photo Albums", @"Camera Roll", nil] autorelease];
{
UIImagePickerController *controller = [[[UIImagePickerController alloc] init] autorelease];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.cameraOverlayView = self.cameraOverlay;
[self performSelector:@selector(removeOverlayView:) withObject:controller afterDelay:0.1f];
controller.allowsEditing = YES;
controller.delegate = self;
// ニュッと出るのでは無く、フェードする
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];