[Swift]Swift #2

Swift #2

func initUI()
{
    //返り値
    println( getMessage() )
    
    //引数のデフォルト値
    println( getMessageOfJeff() )
    
    //Tuples(タプル)
    let message = (2014,"what are you talking about ?")
    let (year,question) = message
    println( message )
    println( "西暦\(year)" )
    println( "question:\(question)" )
}
func getMessage()->String{
    return "I am a pen."
}
func getMessageOfJeff(message:String="Is this a pen ?")->String{
    return message;
}

override func viewDidLoad() {
    super.viewDidLoad()
    initUI()
}

出力結果

I am a pen.
Is this a pen ?
(2014, what are you talking about ?)
西暦2014
question:what are you talking about ?

参考
The Swift Programming Language: The Basics

Tuples can return multiple values from a function as a single compound value.

[Swift]Swift #1

Swift #1

func initUI()
{
    //行の終わりに;(セミコロン)はいらない
    //定数
    let message = "Hello,world!"
    println(message)
    
    //変数
    var n = 34
    println("わたしは\(n*2)歳です")
}

override func viewDidLoad() {
    super.viewDidLoad()
    initUI()
}

出力結果

Hello,world!
わたしは68歳です

[objective-c]UILabelを複製する

UILabelを複製する

-(UILabel*)getCloneUILabelByUILabel:(UILabel*)label
{
    NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:label];
    return [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
}
UILabel*cloneLabel = [self getCloneUILabelByUILabel:modelLabel];

[JavaScript]プロパティ名を指定してソート

プロパティ名を指定してソート

function g_sortOn(_propertyName){
    return function(a,b){
        if( a[_propertyName] > b[_propertyName] )return 1;
        if( a[_propertyName] < b[_propertyName] )return -1;
        return 0;
    }
}
var tmp = targetArray.sort( g_sortOn('name') );

[MySQL]ビット演算#1

ビット演算#1
type(INTEGER)を4ビット右シフトして右端が1であるレコードのidとtypeを取得する。

SELECT id,type FROM target_table_name WHERE type >> 4 & 1 = 1;

[objective-c]2つの日付の差を日数で出す

2つの日付の差を日数で出す

int dayCount = [self getDaysCountByTwoDateString:@"2014-04-01" endDateString:@"2014-04-04"];
-(int)getDaysCountByTwoDateString:(NSString*)startDateString endDateString:(NSString*)endDateString
{
    NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init];
    [inputDateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *startInputDate = [inputDateFormatter dateFromString:startDateString];
    NSDate *endInputDate = [inputDateFormatter dateFromString:endDateString];
    
    float tmp= [endInputDate timeIntervalSinceDate:startInputDate];
    int day=(int)( tmp / (3600.0*24.0) );
    return day;
}

[PHP]URLを取得

URLを取得

$url = (empty($_SERVER["HTTPS"]) ? "http://" : "https://") . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]

[objective-c]animateWithDurationを途中で止める

animateWithDurationを途中で止める

アニメーション実行

[UIView animateWithDuration:10.0f animations:^{
    targetView.frame=CGRectMalke(0.0,0.0,100.0,100.0);
} completion:^(BOOL finished) {
    
}];

アニメーション中止

[UIView setAnimationBeginsFromCurrentState:YES];
[UIView animateWithDuration:0.001 animations:^{
    targetView.alpha = 1.0;
}];