목록전체 글 (393)
나의 발자취
append()와 차이점은, iterable 한 element들을 append한다는 것에 있다. char가 하나로 되어있는 예시를 봐서는 잘 이해가 안됐다. import array numbers = array.array('i', [1, 2, 3]) numbers.append(4) print(numbers) # array('i', [1, 2, 3, 4]) # extend() appends iterable to the end of the array numbers.extend([6, 7]) print(numbers) # array('i', [1, 2, 3, 4, 5, 6, 7]) # not using array library social_network =[] social_network.append("IG") ..
디버깅 시 유용한 팁들 1. #warning syntax를 쓰면 이슈 네비게이터에 표시되므로 나중에 되짚어볼것들을 메모할 수 있다. 변수를 고치고 실행하면 이번에는 아래와 같이 런타임 에러가 뜬다. 2. 디버그 네비게이터를 보는데, 여기서는 CPU, 메모리, 디스크, 네트워크의 리얼타임 실행결과를 볼 수 있다. 프로그램이 의도대로 작동하는지 힌트를 얻기 유용하다. 예를 들어 클라우드 서비스로부터 데이터를 받아오는 함수를 만들었다고 쳤을 때 네트워크 게이지인 KB/s 수치가 0 이상인지 보는 식으로. 여기서 3. 콜 스택도 볼 수 있는데, stact trace라고도 알려져있다. 프로그램이 실행되면 콜스택이라는 데이터 구조에 데이터를 저장한다. 런타임 에러가 발생하면 컴파일러는 콜스택의 상태 로그를 보여주는..
either value or nil 을 가질 수 있는 optional을 언랩핑할때 사용하는 방법 중 하나이다. 옵셔널을 처리하기 위해 스위프트에서는 옵셔널 바인딩 이라는것을 하는데, 옵셔널 바인딩이란 옵셔널을 언랩핑하여 그 값에 접근할 수 있도록 하는것이다. 여기서 if-let은 conditional unwrapping 이다. 이런 식으로 쓰인다. if let newVariable = dictionaryName[optionalValue] { // This code will run if the optional contains a real value }
var easyAsPie = ("easy as", 3.14) Above, we created easyAsPie that holds 2 values: "easy as", and 3.14. If we wanted to access each value individually, we can use dot syntax along with the index of the value: var easyAsPie = ("easy as", 3.14) var firstValue = easyAsPie.0 // "easy as" var secondValue = easyAsPie.1 // 3.14 We can also name a tuple’s elements by prepending each one with a name and ..
View의 body property는 뷰의 구성요소들이 어떻게 레이아웃되어야하는지 계층구조를 짓는 역할을 한다. 이 레이아웃은 주로 VStack, HStack, ZStack을 구성할 때 사용된다. 이들이 구성하는 뷰들을 child view라고 나타낸다. VStack VStack은 vertical하게 뷰를 감싸는 wrapper 역할을 한다. 예를 들어서 두개의 Text 뷰들을 횡단으로 정렬하고 싶으면, VStack을 사용하는 것이다. VStack { Text("Learning to code!") Text("I'm happy") } 만약에 여기서 VStack을 사용하지 않고 두 개의 Text뷰 중 하나를 그냥 뒤에 위치시킨다면 첫번째 Text뷰만 보일것이다. 뷰 모디파이어에는 두가지 카테고리가 있다. 하나는..
a screen in an iOS app is made up of SwiftUI views like Text, Image, Label and Button. Apple defines View as a protocol. struct HappyView: View { var body: some View { Text("Hello, World!") } } 애플에서 View 는 프로토콜로 정의한다. (프로토콜이란 특정 태스크를 완료하기 위해 필요한 요구사항들의 집합의 초석을 정의하는 것) 위 코드에서 View는 구조체다. 구조체는 서로 관련있는 속성(properties)과 함수의 집합을 캡슐화한다. HappyView: View 에서 : View는 HappyView는 View 프로토콜을 따른다는 것을 뜻한다. body..
var randomNumber = Int.random(in: 0...10) switch randomNumber { case let x where x % 2 == 0: print("\(randomNumber) is even") case let x where x % 2 == 1: print("\(randomNumber) is odd") default: print("Invalid") } case에서 임시변수 x를 선언 후 where 문으로 조건 설정 가능(람다같이)
The Log class allows us to create log messages that appear in Logcat. Generally, we should use the following log methods, listed in order from the highest to the lowest priority. Log.e(String, String) // Error -------------------- 이슈를 야기하는 에러 ------------------------no. 1 PRIORITY Log.w(String, String) // Warning -------------------- 아직은 에러가 아니지만 가능성 있는 것 -----no. 2 PRIORITY Log.i(String, String..