Skip to content

Latest commit

 

History

History
74 lines (41 loc) · 1.96 KB

File metadata and controls

74 lines (41 loc) · 1.96 KB

Subscript 1

1) What is subscript? How to declare subscript? Advantages?

Answer:

  • Subscript is a shortcut way of accessing Class or Structure’s collection.
  • Subscript is a feature that enables classes / structures’ to access their values in a shortcut way.
struct School {

	var students: [String] = ["Paige", "Sunghee", "Seunghyun"]

	subscript(index: Int) -> String {
		return students[index]
	}

}

let school: School = School()
print(school.students[0]) // Paige
print(school[1]) // Sunghee

Table Of Contents

Section 1, Data Type

Section 2, Operator

Section 3, Conditional Statement

Section 4, Enum

Section 5, functions

Section 6, struct

Section 7, initializers

Section 8, closures

Section 9, OOP

Section 10, static type vs dynamic type

Section 11, optional

Section 12, generic

Section 13, subscript

Section 14, access specifier

Section 15, higher order function

Section 16, delegate

Section 17, extension

Section 18, Memory Management

Section 19, protocols

Section 20, collections

Section 21, KVO and KVC

Section 22, Exception Handling

Section 23, Framework

Section 24, Objective-C