Last active
August 29, 2015 14:17
-
-
Save el-hoshino/5058f191a60f52fa9e55 to your computer and use it in GitHub Desktop.
【初心者向け?】map メソッドで既存配列から違う型の配列を作る方法 ref: http://qiita.com/lovee/items/0ee298443e4225f3cb3e
This file contains 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
int arrayA[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
int arrayB[10]; | |
for (int i = 0; i < 10; i++) { | |
arrayB[i] = arrayA[i] * arrayA[i]; | |
} |
This file contains 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
let arrayA = [Int](0 ..< 10) | |
var arrayB = [Int]() | |
for element in arrayA { | |
arrayB.append(element * element) | |
} |
This file contains 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
let arrayA = [Int](0 ..< 10) | |
let arrayB = arrayA.map{$0 * $0} |
This file contains 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
let arrayA = [Int](0 ..< 10) | |
let arrayB = arrayA.map{ (element: Int) -> Double in | |
let value = sqrt(Double(element)) | |
return value | |
} |
This file contains 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
let baseView = UIView(frame: CGRectMake(0, 0, 1920, 1080)) | |
let viewTags = [Int](0 ..< 10) | |
for tag in viewTags { | |
let view = UIView(frame: baseView.frame) | |
view.tag = tag | |
baseView.addSubview(view) | |
} | |
//いろいろ操作 | |
let animationViews = viewTags.filter{$0 % 3 == 0}.map{ (tag: Int) -> UIView in | |
let view = baseView.viewWithTag(tag)! | |
return view | |
} | |
UIView.animateWithDuration(1.5, animations: { () -> Void in | |
for view in animationViews { | |
view.alpha = 0 | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment