App Develop

[objective-c]可変長引数のメソッド

ヘッダーファイル

-(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);
}

[objective-c]EGODatabase #5 データ追加

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

[objective-c]EGODatabase #4 データ取得

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

[objective-c]EGODatabase #3 全テーブル名の取得

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

[objective-c]UIImageを複製する

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;
}