ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Swift] Literal, Identifier, Keyword
    swift 2024. 3. 2. 16:23

    Literals 리터럴

     

    1. 의미

      코드에서 의미가 바뀌지 않고 있는 그대로의 의미로 사용되는 것 

     예) 7: 7번째 숫자

     

    2. 예시

      가. Let x = 7

          →7 리터럴, let 상수를 선언하는 키워드, x 상수의 이름.=, = 연산자

      나. Let x = 5 + 7

           →5, 7이 리터럴

      다. Let x2 = x > 7

           →7 리터럴. 2 이름에 포함된 문자일뿐.

     

    3. 종류

    가. Integer Literals

    나. Floating-points Literals

    다. String Literals

    라. Boolean Literals

    마. Nill Literals


    Identifier 식별자

     

    1. 의미

    다른 것과 구별해주는 이름, 명찰, tag

     

    2. 예시

    Let x = 7

    → x가 식별자. 숫자 7을 저장하는 상수의 이름. 코드에 존재하는 다른 상수와 구별한다. 

     

    3. 특징

      가. 유일해야 한다.

      나. 첫 글자는 영문 대소문자 또는 '_' 로, 나머지는 영문자와 숫자의 조합으로 짓는다.

      라. 공백을 추가할 수 없다.

      마. 대소문자가 구별된다. 예)let number = 1, let Number = 1 (컴파일러는 구분할 수 있지만 바람직하지 않음.)

      바. 저장할 값의 성격을 알 수 있도록 짓는다. 예)let memberCount = 1, let lectureCount = 2, Let fixedRate = 3

      사. 유니코드 문자를 사용할 수 있다.  예) let 😀 = b (실제로는 거의 없음.)

     

         

       tip)이름 짓는게 생각보다 어려우므로 레퍼런스를   참고했다가 괜찮은 이름 모아두기.


    Keyword 키워드

     

    1. 의미 

    : 언어가 제공하는 기능을 위해 미리 예약된 단어

     

    2. 예시

    Let x = 7 :  let, 상수를 선언하는 키워드

    Var x = 7 : var, 변수를 선언하는 키워드

     

    3. 종류(하나씩 공부하면서 익숙해지기)

    associatedtype  class  deinit   enum  extension  fileprivate  func  import  init  inout  internal  

    let  open  operator  private  protocol  public  static  struct  subscript  typealias  var  break

    case  continue  default  defer  do  else fallthrough  for  guard  if  in  repeat  return  swich  

    where  while  as  Any  catch  false  is. nill  rethrows. super self  Self  throw  throws  ture  try

    #available  #colorLiteral  column  #else  #elseif  #endif  #file  #fileLiteral #function  #if  

    #imageLiteral  #line  #selector  #sourceLocation  associativity  convenience  dynamic  didSet

    final  get  infix  indirect  lazy  left. mutating  none  nonmutating  optional  override  postfix  

    precedence  prefix Protocol  required  right  set  Type  unowned  weak willSet

     

    4. 특징

      가. 키워드는 특별한 기능을 수행하도록 예약되어 있으므로 식별자로 사용할 수 없다. 

      나. 식별자에 키워드를 포함시켜 사용하는 것은 가능하다. 예) let letnumber = 7

     

    'swift' 카테고리의 다른 글

    [Swift] Naming Convention(CamelCase)  (0) 2024.03.02
    [swift] Variable, Constant  (0) 2024.03.02
    [Swift] Special Character  (1) 2024.03.02
    [Swift] Compile, Link, Run  (0) 2024.03.02
    [Swift] Token, Expression, Statement  (0) 2024.03.02
Designed by Tistory.