Last active
May 11, 2017 08:53
-
-
Save takoikatakotako/c969fea9788ad017d62418b8497550fa to your computer and use it in GitHub Desktop.
Arrayの基本的な操作
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 UIKit | |
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| //配列の宣言 | |
| let languages = ["Ruby","C","Swift","Python","Swift"] | |
| //繰り返して結果を出力 | |
| for language in languages { | |
| print("\(language) ") | |
| //Ruby C Swift Python Swift と出力される | |
| } | |
| //二番目の要素にアクセス | |
| print("二番目の要素にアクセス->\(languages[1]) ") | |
| //二番目の要素にアクセス->C と出力される | |
| //一番最後の要素にアクセス | |
| print("二番目の要素にアクセス->\(languages.last) ") | |
| //一番最後の要素にアクセス->Swift と出力される | |
| //要素数を数える | |
| print("languages配列の要素数は?->\(languages.count) ") | |
| //programings配列の要素数は?->5 | |
| //配列の中にある要素が含まれているのかを調べる | |
| let isContein:Bool = languages.contains("Python") | |
| print("isConteinの中身->\(isContein)") | |
| //isConteinの中身->true | |
| //型明記(以下、INT型で宣言) | |
| var intArray:[Int] = [1,1,2,3,5,8,12,20] | |
| //配列の要素を足し算 | |
| print("\(intArray[1] + intArray[2])") | |
| //3 と出力される, 1+2 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment