[objective-c]UIWindowを取得する
UIWindowを取得する
-(UIWindow*)getWindow{ UIWindow* window=[UIApplication sharedApplication].keyWindow; if(!window)window=[[UIApplication sharedApplication].windows objectAtIndex:0]; return window; }
UIWindowを取得する
-(UIWindow*)getWindow{ UIWindow* window=[UIApplication sharedApplication].keyWindow; if(!window)window=[[UIApplication sharedApplication].windows objectAtIndex:0]; return window; }
iOSのバージョンを取得
NSString*osVersion=[[UIDevice currentDevice] systemVersion];
スクリーンのサイズを取得
CGRect rec=[[UIScreen mainScreen]bounds]; BOOL iphone5=rec.size.height>480.0;
オブジェクトのメモリアドレスを取得
-(double)getMemAddressDouble:(id)n{ NSString*s=[NSString stringWithFormat:@"%p",n]; NSScanner*scan=[NSScanner scannerWithString:s]; double d; [scan scanHexDouble:&d]; return d; } double touchmem=[self getMemAddressDouble:[[touches allObjects] objectAtIndex:0]];
ヘッダーファイル
-(void)myMethod:(NSString*)args, ...NS_REQUIRES_NIL_TERMINATION;
実装部分
-(void)myMethod:(NSString*)args, ... { va_list arguments; va_start(arguments, args); NSString* value = args; NSString* fvalue = args; while (value){ NSLog(@"--value %@",value); value = va_arg(arguments, typeof(NSString*)); } va_end(arguments); }
EGODatabase*db=[EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]]; NSString*sql=[NSString stringWithFormat:@"insert into %@ (id,filename) values(%d,%@)",tableName,id,fileName]; EGODatabaseResult*result=[db executeQuery:sql]; if (result.errorCode) {//failed return NO; } return YES;
参考サイト
enormego/egodatabase · GitHub
https://github.com/enormego/egodatabase
EGODatabase*db=[EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]]; NSString*sql=@"SELECT * FROM tableName WHERE no=1 ORDER BY id;" EGODatabaseResult*result=[db executeQuery:sql]; if (result.errorCode) {//failed return; } NSMutableArray*list=[NSMutableArray arrayWithCapacity:[result count]]; for (EGODatabaseRow*row in result) { [list addObject:[row stringForColumn:@"name"]]; }
参考サイト
enormego/egodatabase · GitHub
https://github.com/enormego/egodatabase
EGODatabase*db=[EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]]; NSString*sql=@"select name from sqlite_master where type = 'table' order by name"; EGODatabaseResult*result=[db executeQuery:sql]; if (result.errorCode) {//failed return; } NSMutableArray*list=[NSMutableArray arrayWithCapacity:[result count]]; for (EGODatabaseRow*row in result) { [list addObject:[row stringForColumn:@"name"]]; }
参考サイト
enormego/egodatabase · GitHub
https://github.com/enormego/egodatabase
EGODatabase*db=[EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]]; NSString*n=@"tableName"; NSString*sql=[NSString stringWithFormat:@"drop table if exists %@",n]; EGODatabaseResult*result=[db executeQuery:sql]; if (result.errorCode) {//failed }else{//success }
参考サイト
enormego/egodatabase · GitHub
https://github.com/enormego/egodatabase
CGImageを使う方法
-(UIImage*)getCUIImage:(UIImage*)img{ return [UIImage imageWithCGImage:[img CGImage]]; }
CGImageを使わない方法
-(UIImage*)getCopyUIImage:(UIImage*)imageToCopy{ UIGraphicsBeginImageContext(imageToCopy.size); [imageToCopy drawInRect:CGRectMake(0, 0, imageToCopy.size.width, imageToCopy.size.height)]; UIImage *copiedImage =UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return copiedImage; }