0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift 型の構成要素

Last updated at Posted at 2018-11-06

随時更新していきます

型の構成要素

Swiftの型は、構造体、クラス、列挙型がある
それぞれ以下の要素が定義されている

定義方法

  • 構造体
struct SomeStruct{}

  • クラス
class SomeClass{}
  • 列挙型
enum SomeEnum{}

インスタンス自身へのアクセス


struct SomeStruct {
    let value = 123

    func printValue() {
        print(self.value)
    }
}
  • インスタンスそのものでなく、インスタンスのプロパティやメソッドにアクセスする場合selfキーワードを省略可能
  • インスタンスのプロパティと同名の変数や定数がスコープ内に存在する場合selfキーワードの明記が必要

struct SomeStruct {
    let value: Int
    
    init(value: Int) {
        self.value = value
    }
}
0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?