2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Swiftの勉強を始めた

2
Posted at

データアナリストの私はアプリ(iOS)を作ろうと考えています。SQLとPythonの経験しかありませんので、無料でSwiftを学べるサイト100 Days of Swift - Hacking with Swiftのコースを始めました。
コースの一環として、毎日の学習メモをSNS(Qiita)で投稿します。

Day 1

Swiftの変数

  • 初めて定義する際に、先頭にvarをつける(e.g. var fruit = "Apple")
  • その後変数の値を変更したい場合、varなしで直接定義できる(e.g. fruit = "Banana")
  • case sensitive
  • type safe: 変数は一つのデータ型しか該当しない

複数行のstrings

  • 一般的のstringは二重引用符で囲んで、改行できない
  • 改行ありのstringを定義するには、3つの二重引用符で囲む
  • 3つの二重引用符は決まった位置に置くべき
    •  var ad_slogan = """
       Big sales
       on
       Apple and Banana.
       """
      
  • コード見た目の目的の改行(結果に改行表示したくない)は、改行間に「\」を入れ

String interpolation

  • 変数の定義に他の変数を参照する方法
  • var score = 85
    var result = "Your score is : \(score)"
    

 
Constant

  • 変数は何回も値を変更できるが、constantは一度定義されると変更できない
  • 定義方法: let taylor = "swift"

Type annotation

  • swiftは自動的にvarとconstantのデータ型を判断して定義できる
  • 手動で定義したい場合は以下のように
  • var score: Double = 85
    let name: String = "John"
    
  • データ型:String, Int, Double, Bool
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?