728x90
곡λΆν λ΄μ©μ μ 리ν κΈμ λλ€.
Chapter 3 λ°μ΄ν° νμ κΈ°λ³Έ
1. Int μ UInt(unsigned Int)
- μ μ
- λ²μ
- Int : μμ μ μλΆν° μμ μ μκΉμ§
- UInt : 0λΆν° μμ μ μκΉμ§. (μ΅λκ°μ΄ Int λ³΄λ€ ν¬λ€)
- Intμ. μ΅λκ° μ΄μ UIntμ μ΅λκ° λ―Έλ§μ μ¬μ©νκ² λλ κ²½μ° μ΄μΈμλ Int κ° μ¬μ© κΆμ₯
var integer: Int = -100
let unsignedInteger: UInt = 50
let largeInteger: Int64 = Int64.max
let smallUnsignedInt : UInt8 = UInt8.min //0
integer = Int(unsignedInteger) //Intμ UIntλ λ€λ₯Έ νμ
μ΄κΈ° λλ¬Έμ νλ³νμ΄ νμνλ€.
2. Bool
- boolean νμ . true/false
var boolean : Bool = true
boolean.toggle() //true - false λ°μ
print("μ λ΅μ? \(boolean)") //false
3. Floatκ³Ό Double
- λΆλμμ νμ . μ€μ
- λ²μ
- Double - 64bits, μ΅μ 15μ리μ μμ§μλ₯Ό νν κ°λ₯
- Float - 32bits, 6μ리μ μμ§μ νν κ°λ₯
let floatValue: Float = 123456.1
let doubleValue: Double = 1234567890.1
4. Character
- λ¬Έμ
- "" ν°λ°μ΄ν μ¬μ©
let alphabetA: Character = "A"
5. String
- λ¬Έμμ΄
- "", ν°λ°μ΄ν μ¬μ©
λ°νκ° | μ€λͺ | μμ | |
append(String or Charter) | Appends the given string or character to this string. : ν΄λΉ λ¬Έμμ΄μ μ£Όμ΄μ§ λ¬Έμμ΄ λλ λ¬Έμ μ΄μ΄ λΆμΈλ€. |
let name: String = "88yhtserof" let str: String = "μ μ΄λ¦μ, " print(str.append(name)) -> μ μ΄λ¦μ, 88yhtserof |
|
+ | + μ°μ°μλ₯Ό ν΅ν΄ λ¬Έμμ΄μ κ²°ν©ν μ μλ€. | let name: String = "88yhtserof" print("μ μ΄λ¦μ, "+ name + " μ λλ€.") -> μ μ΄λ¦μ, 88yhtserof μ λλ€. |
|
λ¬Έμμ΄ λΉκ΅ | Bool | λΉκ΅ μ°μ°μλ₯Ό ν΅ν΄ λ¬Έμμ΄μ λΉκ΅ν μ μλ€. | let name: String = "88yhtserof" let str: String = "μ μ΄λ¦μ, " var sampleBool : Bool = false sampleBool = str != name //true |
hasPrefix(String) | String | Returns a Boolean value indicating whether the string begins with the specified prefix. :λ¬Έμμ΄μ΄ νΉμ μ λμ¬(μ£Όμ΄μ§ λ¬Έμμ΄)λ‘ μμνλμ§ μ νλμ§ λ°ν |
let name: String = "88yhtserof" var sampleBool : Bool = false sampleBool = name.hasPrefix("88") //true |
hasSuffix(String) | String | Returns a Boolean value indicating whether the string ends with the specified suffix. :λ¬Έμμ΄μ΄ νΉμ μ λ―Έμ¬(μ£Όμ΄μ§ λ¬Έμμ΄)λ‘ μμνλμ§ μ νλμ§ λ°ν |
let name: String = "88yhtserof" var sampleBool : Bool = false sampleBool = name.hasSuffix("88") //false |
uppercased() | String | Returns an uppercase version of the string. :λ¬Έμμ΄μ λλ¬Έμλ‘ λ§λ€μ΄ λ°ν |
let name: String = "88yhtserof" var test: String = "" test = name.uppercased() print(test) ->88YHTSEROF |
Dlowercased() | String | Returns a lowercase version of the string. : λ¬Έμμ΄μ μλ¬Έμλ‘ λ§λ€μ΄ λ°ν |
let name: String = "88yhtserof" var test: String = "" test = name.uppercased() print(test) ->88yhtserof |
isEmpty | Bool | A Boolean value indicating whether a string has no characters : λ¬Έμμ΄μ΄ λ¬Έμλ₯Ό κ°μ§κ³ μλμ§ μλμ§ λ°ν |
let name: String = "88yhtserof" var boolean:Bool = false boolean = name.isEmpty //false |
count | Int | The number of characters in a string. : λ¬Έμμ΄μ μλ λ¬Έμμ κ°μ λ°ν |
let name: String = "88yhtserof" print(name.count) ->10 |
""" """ |
μ½λμμμ μ¬λ¬ μ€μ λ¬Έμμ΄μ μ§μ μμ±ν λ μ¬μ© | let str: String = """ μ½λμμμ μ¬λ¬ μ€μ λ¬Έμμ΄μ μ§μ μμ±ν λ μ¬μ© """ |
5.1 νΉμλ¬Έμ
- λ¬Έμμ΄ λ΄μμ μΌμ κΈ°λ₯μ νλ νΉμλ¬Έμ(μ μ΄λ¬Έμ)
- \ λ°±μ¬λμμ νΉμ ν λ¬Έμλ₯Ό μ‘°ν©νμ¬ μ¬μ©
νΉμλ¬Έμ | μ€λͺ |
\n | μ€λ°κΏ λ¬Έμ |
\\ | λ¬Έμμ΄ λ΄μμ λ°±μ¬λμλ₯Ό νννκ³ μ ν λ μ¬μ© |
\" | λ¬Έμμ΄ λ΄μμ ν°λ°μ΄νλ₯Ό νννκ³ μ ν λ μ¬μ© |
\t | ν λ¬Έμ. |
\0 | λ¬Έμμ΄μ΄ λλ¬μμ μ리λ nullλ¬Έμ |
print(#"λ¬Έμμ΄ λ΄λΆμμ νΉμλ¬Έμλ₯Ό μ¬μ©νκΈ° μ«λ€λ©΄ λ¬Έμμ΄ μ, λ€μ #μ λΆμ¬λΌ"#)
>>>λ¬Έμμ΄ λ΄λΆμμ νΉμλ¬Έμλ₯Ό μ¬μ©νκΈ° μ«λ€λ©΄ λ¬Έμμ΄ μ, λ€μ #μ λΆμ¬λΌ
var test:Int = 123
print(#"νΉμλ¬Έμλ₯Ό μ¬μ©νμ§ μμ λλ λ¬Έμμ΄ λ³΄κ°λ²μ μ¬μ©ν μ μλ€. \#(test)"#)
>>>νΉμλ¬Έμλ₯Ό μ¬μ©νμ§ μμ λλ λ¬Έμμ΄ λ³΄κ°λ²μ μ¬μ©ν μ μλ€. 123
6. Any, AnyObjectμ nil
- Any : μ€μννΈμ λͺ¨λ λ°μ΄ν° νμ μ μ¬μ©ν μ μλ€.
var someVar: Any = "88yhtserof"
someVar = 50
someVar = 100.1 //Anyλ‘ μ μΈλ λ³μμ λ¬Έμμ΄, μ μ, μ€μ λλ μ΄λ€ νμ
μ κ°μ΄λΌλ ν λΉν μ μλ€.
- AnyObject : Any 보λ€λ μ‘°κΈ νμ λ μλ―Έλ‘ ν΄λμ€μ μΈμ€ν΄μ€λ§ ν λΉν μ μλ€.
- nil : λ³μ λλ μμμ κ°μ΄ λ€μ΄μμ§ μκ³ λΉμ΄μμμ λνλ΄λλ° μ¬μ©
μΌκ³° - μ€μννΈ νλ‘κ·Έλλ° 5ν (SWIFT5)
Swift 곡μ λ¬Έμ String λ¬Έμ
728x90
'Swift' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[ SWIFT ] λ°μ΄ν° νμ κ³ κΈ(3) - μ΄κ±°ν (0) | 2021.07.30 |
---|---|
[ SWIFT ] λ°μ΄ν° νμ κ³ κΈ (2) - 컬λ μ νμ <λ°°μ΄, λμ λ리, μΈνΈ> (0) | 2021.07.20 |
[ SWIFT ] λ°μ΄ν° νμ κ³ κΈ (1) (0) | 2021.07.19 |
[ SWIFT ] μ€μννΈ μ²μ μμνκΈ° (0) | 2021.07.08 |
[ SWIFT ] μ€μννΈλ? (0) | 2021.07.04 |