Skip to content

Instantly share code, notes, and snippets.

@mutekinootoko
mutekinootoko / iosAppVersionNumber.m
Created February 3, 2016 16:23
ios get version number
- (NSString *)appNameAndVersionNumberDisplayString {
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *majorVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSString *minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"];
return [NSString stringWithFormat:@"%@ (%@)",
majorVersion, minorVersion];
}
@mutekinootoko
mutekinootoko / gist:54d168e43e6722a14090
Last active January 28, 2016 13:27
UITableView scroll text field up above keyboard
// Register notification when the keyboard will be show
[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
// Register notification when the keyboard will be hide
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
#!/bin/bash
for i in {5..0}
do
if [ $i -eq 0 ]
then
echo '2016 hooray~~...'
else
echo $i '..'
fi
sleep 1;
@mutekinootoko
mutekinootoko / avatar.m
Created December 17, 2015 12:07
put avatar on button
// setup code to draw / display avatar
UIView *avatarView = [[UIView alloc] init];
avatarView.frame = CGRectMake(20, 50, 280, 100);
avatarView.layer.borderColor = [UIColor redColor].CGColor;
avatarView.layer.borderWidth = 3.0f;
[self.view addSubview:avatarView];
// do additional loading for avatars
UIButton *avatarButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// the last two values control the size of the button
@mutekinootoko
mutekinootoko / content.m
Last active September 11, 2015 09:28 — forked from fousa/content.m
Localize NSError
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
[userInfo setObject:@"You are not authenticated." forKey:NSLocalizedDescriptionKey];
NSError *error = [NSError errorWithDomain:@"mydomain" code:0 userInfo:userInfo];
@mutekinootoko
mutekinootoko / photoFrameworkDelete.m
Last active September 11, 2015 09:26
photo framework, delete phasset
[PHPhotoLibrary sharedPhotoLibrary] performChanges: ^{
[PHAssetChangeRequest deleteAssets: @[phAssetsInArray.firstObject]];
} completionHandler:^(BOOL success, NSError *error) {
if(error) {
// user cancel deleting operation can cause error too.
}
}];
@mutekinootoko
mutekinootoko / gist:7e44fff4363113d3830e
Created August 25, 2015 12:32
dispatch async, not blocking UI
dispatch_async(dispatch_queue_create("com.marku", DISPATCH_QUEUE_PRIORITY_DEFAULT), ^{
//code
});
@mutekinootoko
mutekinootoko / gist:94e219f9ccf8f6b6d64c
Created July 16, 2015 11:25
generates temp folder
- (NSString*) tempFolderPath {
if(_tempFolderPath == nil) {
NSError* err;
_tempFolderPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]];
[[NSFileManager defaultManager] createDirectoryAtPath:_tempFolderPath withIntermediateDirectories:YES attributes:nil error:&err];
NSLog(@"temporary folder created at %@", _tempFolderPath);
if(err) {
NSLog(@"error when creating temporary folder. %@", err);
// TODO better error handler
}
@mutekinootoko
mutekinootoko / gist:80d365e83a8c8ae661ea
Created June 30, 2015 16:35
UIView Infinite 360 degree rotation animation
- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat;
{
// #import <QuartzCore/QuartzCore.h>
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = repeat;
self.statusView = (StatusView*) ([[UINib nibWithNibName:@"StatusView" bundle:nil]
instantiateWithOwner:nil options:nil][0]);