Seize the day
article thumbnail
[Swift] 특수 문자열 출력하기( \, ")
iOS/문법 2023. 9. 23. 23:30

해당 내용을 알게 된 문제 https://www.acmicpc.net/problem/25083 25083번: 새싹 아래 예제와 같이 새싹을 출력하시오. www.acmicpc.net ✅ 특수 문자열 출력하는 방법! 1️⃣ 역슬래쉬를(\) 출력하려면 print 문에 역슬래쉬(\)를 2번 작성해야 한다. print(" ,r'\"7") print("r`-_ ,' ,/") print(" \\. \". L_r'") print(" `~\\/") print(" |") print(" |") ✅ 역슬래쉬와 큰 따옴표를 출력하기 위해 앞에 역슬래쉬 ( \ )를 붙인 코드 2️⃣ 큰따옴표(")를 출력하려면 print 문에 역슬래쉬(\) + 큰따옴표(")를 작성해야 한다. print(""" ,r'\"7 r`-_ ,' ,/ \\..

article thumbnail
[Swift] 문자열 쪼개기(components VS split)
iOS/문법 2023. 9. 22. 16:37

Component 공식 문서: https://developer.apple.com/documentation/foundation/nsstring/1413214-components components(separatedBy:) | Apple Developer Documentation Returns an array containing substrings from the receiver that have been divided by a given separator. developer.apple.com func components(separatedBy separator: String) -> [String] 파라미터의 개수 - components 메서드의 경우는 매개변수가 separatedBy 하나만 있고 매개변수로 ..

article thumbnail
[Swift] 뒤집기 - reversed() / 자리 바꾸기 - swapAt(_:_:)
iOS/문법 2023. 9. 22. 14:56

reversed() 공식 문서: https://developer.apple.com/documentation/foundation/data/1780245-reversed/ reversed() | Apple Developer Documentation Returns a view presenting the elements of the collection in reverse order. developer.apple.com - 컬렉션의 요소를 역순으로 나타내는 뷰를 반환한다. func reversed() -> ReversedCollection - 컬렉션의 순서를 뒤집을 때 사용한다. - String 문자열도 배열이고 배열은 컬렉션이므로 뒤집을 수 있다! - 리턴타입이 ReversedCollection 이므로, 필요에..

article thumbnail
[swift] 변수,상수,배열,딕셔너리,조건문,반복문,옵셔널 개념정리
iOS/문법 2023. 7. 19. 16:36

변수와 상수 변수(variable) 은 var, 상수(constant)는 let 으로 사용합니다. var name = "Lee SeongHyeon" let birthday = 1999 만약 이름을 바꾸고 싶다면 바꿀 수 있지만 생일은 바꿀 수 없습니다.(변수와 상수 차이) name = "Hong gildong" // 가능 birthday = 2000 // 불가능 또한 swift는 정적 타이핑 언어로, 변수나 상수를 정의할 때 그 자료형(타입)이 어떤 것인지 명시를 해주어야 합니다. var name: String = "Lee SeongHyeon" let birthday: Int = 1999 var height: Float = 178.5 만약 다른 자료형끼리 연산을 하려고 하면 컴파일 에러가 발생합니다. 따..