This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ 条件にマッチする要素のみを取り出したい場合 | |
func filter(array: []) { | |
let newArray = array.filter { $0 < 3 } | |
// newArray -> [1,2] | |
} | |
// 各要素に対して処理を行い、かつ戻り値が必要ない場合 | |
func forEach(array: []) { | |
array.forEach { | |
print("\($0)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// FadeInOut.swift | |
// | |
// | |
// Usage | |
// フェードイン | |
// 完了タイミングで何かしたい場合はクロージャーも記述 | |
// FadeView.fadeIn(type: .Slow) { [weak self] in | |
// println("FadeIn 完了") | |
// } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Color.swift | |
// | |
// | |
// Usage | |
// UIColor.HexColor.Red | |
// UIColor.RGBColor.Red | |
// | |
import Foundation | |
import UIKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func a() { | |
closure({ (a: Int, b: Int) -> Bool in | |
return a > b | |
}) | |
closure() { (a, b) in | |
return a > b | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MotionShake.swift | |
// | |
override func canBecomeFirstResponder() -> Bool { | |
return true | |
} | |
override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent?) { | |
if event!.type == UIEventType.Motion && event!.subtype == UIEventSubtype.MotionShake { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pattern1 | |
-(void)a { | |
[self closure:^BOOL(int a, int b){ | |
return a > b; | |
}]; | |
} | |
-(void)closure:(BOOL(^)(int, int))close { | |
NSLog(@"%@", close(4,2) == 1?@"YES" : @"NO"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CLAlertController.h | |
// | |
// Usage | |
// CLAlertController* AlertController = [[CLAlertController alloc]initWithTitle:@"タイトル" message:@"本文" delegate:self parent:parent]; | |
// | |
// [AlertController addView:view]; | |
// [AlertController addActionWithTitle:@"いいえ"]; | |
// [AlertController addActionWithTitle:@"OK"]; | |
// [AlertController show]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ユーザーからの入力を受け取る | |
modelへ入力を伝える |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Kotlin {} | |
extension Kotlin { | |
func lets<R>(_ closure: (Self) -> R) -> R { | |
return closure(self) | |
} | |
func apply(closure: (Self) -> Void) -> Self { | |
closure(self) | |
return self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Collections; | |
class Decimal { | |
static int DECIMAL_10 = 20; | |
public static void main(String[] args) { | |
System.out.println(convertDecimal(DECIMAL_10, 2)); // 10100 |