<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 강기환 on Medium]]></title>
        <description><![CDATA[Stories by 강기환 on Medium]]></description>
        <link>https://medium.com/@sandwich5011?source=rss-e7d2d95f9c69------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*iUdmqyasVPP1xtjG</url>
            <title>Stories by 강기환 on Medium</title>
            <link>https://medium.com/@sandwich5011?source=rss-e7d2d95f9c69------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:45:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sandwich5011/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[iOS 스터디 5주차 Ch28]]></title>
            <link>https://medium.com/gdsc-tuk/ios-%EC%8A%A4%ED%84%B0%EB%94%94-5%EC%A3%BC%EC%B0%A8-ch28-2785d63468?source=rss-e7d2d95f9c69------2</link>
            <guid isPermaLink="false">https://medium.com/p/2785d63468</guid>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[강기환]]></dc:creator>
            <pubDate>Thu, 17 Nov 2022 06:07:54 GMT</pubDate>
            <atom:updated>2022-11-17T06:07:54.369Z</atom:updated>
            <content:encoded><![CDATA[<h3>SwiftUI에서 콘텍스트 메뉴 바인딩하기</h3><p>SwiftUI에서 콘텍스트 메뉴는 사용자가 뷰를 롱 프레스를 했을 때 나타나는 메뉴다. 콘텍스트 메뉴에 속한 각 메뉴 항목은 일반적으로 Text 뷰와 선택사항인 Image 뷰와 함께 선택했을 때 동작을 수행하도록 구성된 Button 뷰를 포함한다.</p><h3>1. 콘텍트 뷰 준비하기</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*JyJihVBzwwp6QupK.png" /></figure><h3>2. 콘텍스트 메뉴 추가하기</h3><p>콘텍스트 메뉴는 contextMenu() 수정자를 사용해 메뉴 항목으로 제공되는 뷰를 선언하여 SwiftUI의 뷰에 추가된다. ContentView.swift 파일의 body 뷰를 다음과 같이 수정하여 콘텍스트 메뉴에 메뉴 항목을 추가하자.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c4Z3jTQHm1f2JAvQ.png" /></figure><p>마지막으로, 포그라운드와 백그라운드 상태 프로퍼티에 할당된 값을 변경하는 코드를 두 개의 버튼에 추가하자</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/0*LYjiyQsGP2iEFO89.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2785d63468" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gdsc-tuk/ios-%EC%8A%A4%ED%84%B0%EB%94%94-5%EC%A3%BC%EC%B0%A8-ch28-2785d63468">iOS 스터디 5주차 Ch28</a> was originally published in <a href="https://medium.com/gdsc-tuk">GDSC TUK</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS스터디 5주차 Ch27]]></title>
            <link>https://medium.com/gdsc-tuk/ios%EC%8A%A4%ED%84%B0%EB%94%94-5%EC%A3%BC%EC%B0%A8-ch27-35b6f1080010?source=rss-e7d2d95f9c69------2</link>
            <guid isPermaLink="false">https://medium.com/p/35b6f1080010</guid>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[강기환]]></dc:creator>
            <pubDate>Thu, 17 Nov 2022 06:06:45 GMT</pubDate>
            <atom:updated>2022-11-17T06:06:45.831Z</atom:updated>
            <content:encoded><![CDATA[<h3>SwiftUI에서 탭 뷰 만들기</h3><h3>1. SwiftUI 탭 뷰 개요</h3><p>SwiftUI에서 탭 뷰는 TabView 컨테이너 뷰를 사용하여 생성되며, 사용자가 이동할 화면들을 나타내는 하위 뷰들로 구성된다.</p><p>TabView는 하위 뷰들 사이를 이동하는 데 사용될 탭 아이템을 가진 탭 바를 레이아웃 하단에 표시한다. 탭 아이템은 수정자를 사용하여 각각의 콘텐트 뷰에 적용되며, Text 뷰와 Image 뷰로 구성되도록 할 수 있다. 다른 뷰 타입들은 탭 아이템에 지원되지 않는다.</p><p>탭 아이템에 태그를 추가하면 프로그램적으로 현재 선택된 탭을 제어할 수도 있다.</p><h3>2. 콘텐트 뷰 추가하기</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/0*iDi2Piudf0DEuqZO.png" /></figure><h3>3. 탭 아이템 추가하기</h3><p>프리뷰를 보면 첫 번째 콘텐트 뷰와 함께 탭 바가 화면 하단에 표시된다. 탭 아이템을 추가하지 않았기 때문에 탭 바는 현재 비어있다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/0*iZ60gBbneF0SDrZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*gKxgR3fWw-paOD4W.png" /></figure><h3>4. 탭 아이템 태그 추가하기</h3><p>코드로 현재 선택된 탭을 제어하려면 태그가 각 탭 아이템에 추가되어야 하며, 현재의 선택을 저장하기 위해 상태 프로퍼티를 다음과 같이 선언한다.<br>TabView의 현재 선택 값과 selection 상태 프로퍼티를 바인딩한다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Iwk7oYJBibXXVLHR.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35b6f1080010" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gdsc-tuk/ios%EC%8A%A4%ED%84%B0%EB%94%94-5%EC%A3%BC%EC%B0%A8-ch27-35b6f1080010">iOS스터디 5주차 Ch27</a> was originally published in <a href="https://medium.com/gdsc-tuk">GDSC TUK</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS스터디 4주차 CH21]]></title>
            <link>https://medium.com/gdsc-tuk/ios%EC%8A%A4%ED%84%B0%EB%94%94-4%EC%A3%BC%EC%B0%A8-ch21-3cc91e80dea3?source=rss-e7d2d95f9c69------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cc91e80dea3</guid>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[강기환]]></dc:creator>
            <pubDate>Sun, 13 Nov 2022 08:33:12 GMT</pubDate>
            <atom:updated>2022-11-13T08:33:12.755Z</atom:updated>
            <content:encoded><![CDATA[<h3>상태, Observable 객체, Environment 객체로 작업하기</h3><p>SwiftUI는 상태 프로퍼티, Observable 객체, Environment 객체를 제공하며, 이들 모두는 사용자 인터페이스의 모양과 동작을 결정하는 상태를 제공한다. SwiftUI에서 사용자 인터페이스 레이아웃을 구성하는 뷰는 코드 내에서 직접 업데이트하지 않는다. 그 대신, 뷰와 바인딩된 상태 객체가 시간이 지남에 따라 변하면 그 상태에 따라 자동으로 뷰가 업데이트된다.</p><h3>1. 상태 프로퍼티</h3><p>상태 프로퍼티는 상태에 대한 가장 기본적인 형태이며, 뷰 레이아웃의 현재 상태를 저장하기 위해서만 사용된다. @State 프로퍼티 래퍼를 사용하여 선언된다.</p><pre>struct ContentView: View {<br>	<br>    @State private var wifiEnabled = true<br>    @State private var userName = &quot;&quot;<br>    <br>    var body: some View {<br>.<br>.</pre><p>상태 값은 해당 뷰에 속한 것이기 때문에 private 프로퍼티로 선언되어야 한다.<br>상태 프로퍼티에 의존하는 모든 뷰는 최신 값이 반영되도록 업데이트된다.</p><p>상태 프로퍼티를 선언했다면 레이아웃에 있는 뷰와 바인딩을 할 수 있다. 바인딩이 되어 있는 뷰에서 변경이 일어나면 해당 상태 프로퍼티에 자동으로 반영된다.<br>상태 프로퍼티와의 바인딩은 프로퍼티 이름 앞에 ‘$’을 붙이면 된다.</p><pre>struct ContentView: View {<br>	<br>    @State private var wifiEnabled = true<br>    @State private var userName = &quot;&quot;<br>    <br>    var body: some VIew {<br>    	VStack {<br>        	Toggle(isOn: $wifiEnabled) {<br>            	Text(&quot;Enable Wi-Fi&quot;)<br>            }<br>        	TextField(&quot;Enter user name&quot;, text: $userName)<br>            Text(userName)<br>            Image(systemName: wifiEnabled ? &quot;wifi&quot; : &quot;wifi.slash&quot;)<br>        }<br>    }<br>}</pre><h3>2. 상태 바인딩</h3><pre>struct ContentView: View {<br>	<br>    @State private var wifiEnabled = true<br>    @State private var userName = &quot;&quot;<br>    <br>    var body: some VIew {<br>    	VStack {<br>        	Toggle(isOn: $wifiEnabled) {<br>            	Text(&quot;Enable Wi-Fi&quot;)<br>            }<br>        	TextField(&quot;Enter user name&quot;, text: $userName)<br>            Text(userName)<br>            WifiImageView(wifiEnabled: $wifiEnabled)<br>        }<br>    }<br>}</pre><pre>struct WifiImageView: View {<br>	<br>    @Binding var wifiEnabled : Bool<br>	var body: some View {<br>    	Image(systemName: wifiEnabled ? &quot;wifi&quot; : &quot;wifi.slash&quot;)<br>    }<br>}</pre><p>어떤 뷰가 하나 이상의 하위 뷰를 가지고 있으며 동일한 상태 프로퍼티에 대해 접근해야 하는 경우 @Binding 프로퍼티 래퍼를 이용하면 해결된다.</p><h3>3. Observable 객체</h3><p>Observable 객체는 여러 다른 뷰들이 외부에서 접근할 수 있는 영구적인 데이터를 표현하기 위해 사용된다. 일반적으로 시간에 따라 변경되는 하나 이상의 데이터 값을 모으고 관리하는 역할을 담당한다. 또한, 타이머나 알림과 같은 이벤트를 처리하기 위해 사용될 수도 있다.</p><p>Observable 객체는 게시된 프로퍼티로서 데이터 값을 게시한다. 그런 다음, 게시자를 구독하여 게시된 프로퍼티가 변경될 때마다 업데이트를 받는다.</p><p>Combine 프레임워크에 포함되어 있는 Observable 객체는 게시자와 구독자 간의 관계를 쉽게 구축할 수 있도록 iOS 13에 도입되었다.<br>@Published 프로퍼티 래퍼를 사용하면 래퍼 프로퍼티 값이 변경될 때마다 모든 구독자에게 업데이트를 알리게 된다.</p><pre>import Foundation<br>import Combine<br>import SwiftUI</pre><pre>class DemoData : ObservableObject {</pre><pre>	@Published var userCount = 0<br>    @Published var currentUser = &quot;&quot;<br>    <br>    init() {<br>    	// 데이터 초기화<br>    	updateData()<br>    }<br>    <br>    func updateData() {<br>    	// 데이터 최산 상태 유지<br>    }<br>}</pre><pre>struct ContentView: View {<br>	<br>    @ObservedObject var demoData : DemoData<br>    <br>    var body: some View {<br>    	Text(&quot;\(demoData.currentUser), you are user number \(demoData.userCount)&quot;)<br>    }<br>}</pre><pre>struct ContentView_Previews: PreviewProvide {<br>	static var previews: some View {<br>    	ContentView(demoData: DemoData())<br>    }<br>}</pre><h3>4. Environment 객체</h3><p>어떤 뷰에서 다른뷰로 이동하는데 이동될 뷰에서도 동일한 구독 객체에 접근해야 한다면, 이동할 때 대상 뷰로 구독 객체에 대한 참조체를 전달해야 한다.</p><pre>@ObservedObject var demoData: DemoData = DemoData()<br>.<br>.<br>NavigationLink(destination: SecondView(demoData)) {<br>	Text(&quot;Next Screen&quot;)<br>}</pre><p>NavigationLink는 SecondView라는 이름의 다른뷰로 이동하기 위해 사용되며, demoData객체에 대한 참조체를 전달한다.<br>앱 내의 여러 뷰가 동일한 구독 객체에 접근해야 하는 경우에는 Environment 객체를 사용하는 것이 더 합리적일 수 있다.<br>Environment 객체는 SwiftUI 환경에 저장되며, 뷰에서 뷰로 전달할 필요 없이 모든 뷰가 접근할 수 있다.<br>Environment 객체를 구독해야 하는 객체는 @EnvironmentObject 프로퍼티 래퍼를 이용하여 해당 객체를 참조하면 된다.</p><pre>@EnvironmentObject var demoData: DemoData</pre><p>Environment 객체는 옵저버 내에서 초기화될 수 없으므로 접근하는 뷰가 화면을 설정하는 동안 구성해야 한다. SceneDelegate.swift 파일의 willConnectTo 메서드를 수정해야 한다.</p><pre>let contentView = ContentView()</pre><pre>let demoData = DemoData()</pre><pre>if let windowScene = scene as? UIWindowScene {<br>	let window = UIWindow(windowScene: windowScene)<br>    window.rootViewController = UIHostingController(rootView: contentView.environmentObject(demoData))<br>    self.window = window<br>    window.makeKeyAndVisible()<br>}</pre><p>SwiftUI 프리뷰 캔버스 내에서 Environment 객체를 사용하려면 PreviewProvider 선언부를 다음과 같이 수정해야 한다.</p><pre>struct ContentView_Previews: PreviewProvider {<br>	static var previews: some View {<br>    	<br>        ContentView().environmentObject(DemoData())<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cc91e80dea3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gdsc-tuk/ios%EC%8A%A4%ED%84%B0%EB%94%94-4%EC%A3%BC%EC%B0%A8-ch21-3cc91e80dea3">iOS스터디 4주차 CH21</a> was originally published in <a href="https://medium.com/gdsc-tuk">GDSC TUK</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS스터디 4주차 CH20]]></title>
            <link>https://medium.com/gdsc-tuk/ios%EC%8A%A4%ED%84%B0%EB%94%94-4%EC%A3%BC%EC%B0%A8-ch20-cad3694c017?source=rss-e7d2d95f9c69------2</link>
            <guid isPermaLink="false">https://medium.com/p/cad3694c017</guid>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[강기환]]></dc:creator>
            <pubDate>Sun, 13 Nov 2022 08:26:45 GMT</pubDate>
            <atom:updated>2022-11-13T08:26:45.927Z</atom:updated>
            <content:encoded><![CDATA[<h3>SwiftUI 스택과 프레임</h3><h3>1. SwiftUI 스택</h3><p>SwiftUI는 VStack(수직), HStack(수평), ZStack(중첩되게 배치하는 뷰) 형태인 3개의 스택 레이아웃 뷰를 제공한다. 스택은 SwiftUI View 파일 내에 하위 뷰들이 스택 뷰에 포함되도록 선언된다.</p><pre>struct ContentView: View {<br>	var body: some View {<br>    	HStack {<br>        	Image(systemName: &quot;goforward.10&quot;)<br>            Image(systemName: &quot;goforward.15&quot;)<br>            Image(systemName: &quot;goforward.30&quot;)<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/0*EcfPR4MnfnK0qX5k.png" /></figure><pre>VStack{<br>	Image(systemName: &quot;goforward.10&quot;)<br>    Image(systemName: &quot;goforward.15&quot;)<br>    Image(systemName: &quot;goforward.30&quot;)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/50/0*DLq3i3iDhY-ighJ4.png" /></figure><p>기존의 컴포넌트를 스택에 포함시키려면 컴포넌트를 스택 선언부 안에 직접 넣거나 코드 에디터에 있는 컴포넌트 위에 마우스 포인터를 올리고 키보드의 Command 키를 누른 상태에서 컴포넌트를 클릭하여 할 수 있다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/0*uGGQG5uT_JpXKTQJ.png" /></figure><p>다른 스택 안에 스택을 포함시켜 복잡한 레이아웃을 간단하게 설계할 수 있다.</p><pre>VStack {<br>	Text(&quot;Financial Results&quot;)<br>    	.font(.title)<br>        <br>    HStack {<br>    	Text(&quot;Q1 Sales&quot;)<br>        	.font(.headline)<br>        <br>        VStack {<br>        	Text(&quot;January&quot;)<br>            Text(&quot;February&quot;)<br>            Text(&quot;March&quot;)<br>        }<br>        <br>        VStack {<br>        	Text(&quot;$1000&quot;)<br>            Text(&quot;$200&quot;)<br>            Text(&quot;$3000&quot;)<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/0*iom6oZUseygnZt3S.png" /></figure><h3>2. Spacer, alignment, padding</h3><p>Spacer를 스택 안에서 사용하면 Spacer는 배치된 뷰들의 간격을 제공하기 위하여 스택의 방향에 따라 유연하게 확장/축소된다.</p><pre>HStack(alignment: .top, spacing: 15) {</pre><pre>	Text(&quot;Q1 Sales&quot;)<br>    	.font(.headline)<br>    Spacer()<br>    VStack(alignment: .leading) {<br>    	Text(&quot;January&quot;)<br>        Text(&quot;February&quot;)<br>        Text(&quot;March&quot;)<br>    }<br>    Spacer()<br>.<br>.<br>.</pre><p>alignment : 스택의 정렬은 스택이 선언될 때 정렬 값을 지정하면 된다.<br>spacing : 간격 값을 지정할 수 있다.</p><p>SwiftUI는 레이아웃, 콘텐트, 화면 크기에 대한 최적의 간격을 자동으로 사용한다.</p><pre>Text(&quot;Hello World!&quot;)<br>	.padding()</pre><p>수정자의 매개변수로 값을 전달하여 간격을 지정할 수 있다.</p><pre>Text(&quot;Hello World!&quot;)<br>	.padding(10)</pre><p>지정된 값이 있던 없던 뷰의 특정 방향에만 적용할 수 있다.</p><pre>Text(&quot;Hello World!&quot;)<br>	.padding(.top, 10)</pre><pre>HStack(alignment: .center, spacing: 15) {</pre><pre>	Text(&quot;Financial Results&quot;)<br>    	.font(.title)<br>    <br>    HStack(alignment: .top) {<br>    	Text(&quot;Q1 Sales&quot;)<br>        	.font(.headline)<br>        Spacer()<br>        VStack(alignment: . leading) {<br>        	Text(&quot;January&quot;)<br>        	Text(&quot;February&quot;)<br>        	Text(&quot;March&quot;)<br>    	}<br>        Spacer()<br>        VStack(alignment: .leading) {<br>        	Text(&quot;$10000&quot;)<br>            Text(&quot;$200&quot;)<br>            Text(&quot;$3000&quot;)<br>        }<br>        .padding(5)<br>    }<br>    .padding(5)<br>}<br>.padding(5)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/0*dTnz8sIKi8hZ08x6.png" /></figure><h3>3. 컨테이너의 자식 뷰 제한</h3><p>컨테이너 뷰는 직접적인 하위 뷰를 10개로 제한한다. 스택 컨테이너가 10개 이상의 자식 뷰를 담으면 오류가 발생한다.<br>스택에 포함된 직접적인 자식 뷰가 10개를 넘어야 한다면 Group 뷰를 사용할 수 있다.</p><pre>VStack {<br>	<br>    Group {<br>    	Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>    }<br>    <br>    Group {<br>    	Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>        Text(&quot;Sample text&quot;)<br>    }<br>}</pre><p>Group에 뷰들을 포함시키고 숨기는 명령을 주면 하나의 명령으로 모든 뷰를 숨길 수 있다.</p><h3>4. 텍스트 줄 제한과 레이아웃 우선순위</h3><p>디폴트로, HStack은 Text 뷰를 한 줄로 보여준다.</p><pre>HStack { <br>	Image(systemName: &quot;airplane&quot;) <br>    Text(&quot;Flight times:&quot;) <br>    Text(&quot;London&quot;) <br>} <br>.font(.largeTitle)</pre><p>스택이 충분한 공간을 보유</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*rV70MSPIVE9M9p2N.png" /></figure><p>스택이 충분한 공간을 가지고 있지 않은 경우</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*fPaM8ElksEE_qjdc.png" /></figure><p>텍스트를 몇 줄로 표현할지는 lineLimit() 수정자를 사용하면 정할 수 있다.</p><pre>HStack { <br>	Image(systemName: &quot;airplane&quot;) <br>    Text(&quot;Flight times:&quot;) <br>    Text(&quot;London&quot;) <br>} <br>.font(.largeTitle)<br>.lineLimit(1)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/0*s3JyFbbMHZeAGVE1.png" /></figure><p>뷰들 간에 우선순위는 layoutPriority() 수정자를 사용해서 줄 수 있다.</p><pre>HStack { <br>	Image(systemName: &quot;airplane&quot;) <br>    Text(&quot;Flight times:&quot;) <br>    Text(&quot;London&quot;).layoutPriority(1)<br>} <br>.font(.largeTitle)<br>.lineLimit(1)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/0*NWLW8ht6POt73KYT.png" /></figure><h3>5. SwiftUI 프레임</h3><p>디폴트로, 뷰는 자신의 콘텐트와 자신이 속한 레이아웃에 따라 자동으로 크기가 조절된다. 뷰 자체가 특정 크기나 영역에 맞아야 할때는 frame 수정자를 사용한다.</p><pre>Text(&quot;Hello World&quot;)<br>	.font(.largeTitle)<br>    .border(Color.black)<br>    .frame(Width: 100, height: 100, alignment: .center)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/0*va4ee7gNEIcrUkpq.png" /></figure><p>frame을 사용하여 텍스트가 길어지면 잘리는 현상을 해결할 수 있다.</p><pre>Text(&quot;Hello World, how are you?&quot;)<br>	.font(.largeTitle)<br>    .border(Color.black)<br>    .frame(minWidth: 100, maxWidth: 300, minheight: 100, <br>    		maxHeight: 100, alignment: .center)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*IRp12fGwH4ieNGKI.png" /></figure><p>최솟값과 최댓값을 각각 0과 무한대로도 설정 가능하다.</p><pre>.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)</pre><p>디폴트로, framea은 화면을 채울 때 화면의 안전 영역을 준수한다. 안전 영역 밖에까지 확장되도록 frame을 구성하려면 edgesIgnoringSafeArea() 수정자를 사용하면 안전 영역을 무시하게 된다.</p><h3>6. frame, GeometryReader</h3><p>프레임은 뷰들을 담고 있는 컨테이너의 크기에 따라 조절되도록 구현할 수 있다.<br>GeometryReader로 뷰를 감싸고 컨테이너의 크기를 식별하기 위한 리더(reader)를 이용하여 할 수 있다. 리더는 프레임의 크기를 계산하는 데 사용된다.</p><pre>GeometryReader { geometry in<br>	VStack {<br>    	Text(&quot;Hello World, how are you?&quot;)<br>        	.font(.largeTitle)<br>            .frame(width: geometry.size.width / 2,<br>            	height: (geometry.size.height / 4) * 3)<br>        Text(&quot;Goodbye World&quot;)<br>        	.font(.largeTitle)<br>            .frame(width: geometry.size.width / 3,<br>            	height: geometry.size.height / 4)<br>    }<br>} .border(Color.black)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*wtzZG2GW9TrMoOKd.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cad3694c017" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gdsc-tuk/ios%EC%8A%A4%ED%84%B0%EB%94%94-4%EC%A3%BC%EC%B0%A8-ch20-cad3694c017">iOS스터디 4주차 CH20</a> was originally published in <a href="https://medium.com/gdsc-tuk">GDSC TUK</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ㅁㄴㅇㅁㄴㅇ]]></title>
            <link>https://medium.com/@sandwich5011/%E3%85%81%E3%84%B4%E3%85%87%E3%85%81%E3%84%B4%E3%85%87-f11c1ab3de32?source=rss-e7d2d95f9c69------2</link>
            <guid isPermaLink="false">https://medium.com/p/f11c1ab3de32</guid>
            <dc:creator><![CDATA[강기환]]></dc:creator>
            <pubDate>Thu, 03 Nov 2022 08:20:47 GMT</pubDate>
            <atom:updated>2022-11-03T08:20:47.785Z</atom:updated>
            <content:encoded><![CDATA[<p>ㅁㅇㅁㅇㄴㅁㄴㅇ</p><p>ㅁㄴㅇㅁㅇㄴ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f11c1ab3de32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS스터디 3주차 Ch10]]></title>
            <link>https://medium.com/gdsc-tuk/ios%EC%8A%A4%ED%84%B0%EB%94%94-3%EC%A3%BC%EC%B0%A8-ch10-20ecebae7693?source=rss-e7d2d95f9c69------2</link>
            <guid isPermaLink="false">https://medium.com/p/20ecebae7693</guid>
            <dc:creator><![CDATA[강기환]]></dc:creator>
            <pubDate>Thu, 03 Nov 2022 08:13:44 GMT</pubDate>
            <atom:updated>2022-11-03T08:13:44.180Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. 스위프트 클래스 선언</h3><pre>class 새로운 클래스 이름: 부모 클래스 {<br>	// 프로퍼티<br>    // 인스턴스 메서드<br>    // 타입 메서드<br>}</pre><p>프로퍼티 : 클래스 내에 포함될 변수와 상수<br>인스턴스, 타입 메서드 : 특정 작업을 수행하는 클래스 고유의 함수</p><h3>2. 프로퍼티, 메서드</h3><pre>class BankAccount {							<br>	var accountBalance: Float = 0						<br>    var accountNumber: Int = 0							// 프로퍼티<br>    <br>    func displayBalance() {								// 인스턴스 메서드<br>    	print(&quot;Number \(accountNumber)&quot;)<br>        print(&quot;Current balance is \(accountBalance)&quot;)<br>    }<br>    <br>    class func getMaxBalance() -&gt; Float {				// 타입 메서드<br>    	return 100000.00<br>    }<br>}</pre><p>객체지향 프로그래밍의 핵심 목적은 데이터 캡슐화이다. 클래스 내의 캡슐화된 데이터를 프로퍼티 라고 하고 프로퍼티를 가지고 작업을 할 수 있는것이 메서드이다. 먼저, 타입 메서드는 클래스 레벨에서 동작하고 인스턴스 메서드는 클래스의 인스턴스에 대한 작업만 한다. 타입 메서드는 선언부 앞에 class 키워드가 붙는다.</p><h3>3. 클래스 인스턴스 초기화 및 소멸</h3><pre>class BankAccount {							<br>	var accountBalance: Float = 0						<br>    var accountNumber: Int = 0							// 프로퍼티<br>    <br>    init(number: Int, balance: Float) {<br>    	accountNumber = number<br>        accountBalance = balance<br>    }<br>    <br>    deinit{												// 소멸자<br>    	// 필요한 정리 작업 수행<br>    }<br>    <br>    func displayBalance() {								// 인스턴스 메서드<br>    	print(&quot;Number \(accountNumber)&quot;)<br>        print(&quot;Current balance is \(accountBalance)&quot;)<br>    }<br>    <br>    class func getMaxBalance() -&gt; Float {				// 타입 메서드<br>    	return 100000.00<br>    }<br>}</pre><p>클래스는 인스턴스를 생성하는 시점에 해야 할 초기화 작업이 있을 수 있다. 이 작업은 클래스의 init 메서드 안에 구현된다. 반대로, 스위프트 런타임 시스템에 의해 클래스 인스턴스가 없어지기 전에 해야 할 정리 작업은 클래스 안에 소멸자를 구현하면 할 수 있다.</p><pre>// var account1: BankAccount = BankAccout()<br>var account1 = BankAccount(number: 12312312, balance: 400.54)</pre><p>클래스의 인스턴스를 생성할 때 위와 같은 코드로 초기화할 수 있다.</p><h3>4. 메서드 호출 및 접근하기</h3><pre>var balance1 = acount1.accountBalance<br>account1.accountBalance = 6789.98<br>account1.displayBalance()<br>var maxAllowed = BankAccount.getMaxBalance()	// 타입 메서드 호출</pre><p>인스턴스의 메서드와 프로퍼티는 점 표기법을 이용하여 호출 및 접근할 수 있다. 타입 메서드는 클래스 인스턴스가 아니라 클래스에서 호출되어야 한다.</p><h3>5. 저장 프로퍼티와 연산 프로퍼티</h3><pre>class BankAccount {							<br>	var accountBalance: Float = 0						<br>    var accountNumber: Int = 0							<br>    <br>    var balanceLessFees: Float {					// 연산 프로퍼티<br>    	get {<br>        	return accountBalance - fees<br>        }<br>        <br>        set(newBalance) {<br>        	accountBalance = newBalance - fees<br>        }<br>    }<br>    <br>    init(number: Int, balance: Float) {<br>    	accountNumber = number<br>        accountBalance = balance<br>    }<br>.<br>.<br>.</pre><pre>}</pre><pre>var balance1 = account1.balanceLessFees<br>account1.balanceLessFees = 12123.12</pre><p>저장 프로퍼티는 상수나 변수에 담기는 값이다. 반면 연산 프로퍼티는 프로퍼티에 값을 설정하거나 가져오는 시점에서 어떤 계산이나 로직에 따라 처리된 값이다.</p><h3>6. 지연 저장 프로퍼티</h3><pre>class MyClass() {</pre><pre>lazy var myProperty: String = {<br>    	var result = resourceIntensiveTask()<br>        result = processData(data: result)<br>        return result<br>    }()<br>.<br>.<br>.</pre><p>프로퍼티를 초기화할때 클로저를 이용하여 프로퍼티를 초기화할 수 있다. 이때 프로퍼티를 lazy로 선언하면 프로퍼티가 최초로 접근될 때만 초기화된다.<br>* 지연 프로퍼티는 반드시 변수(var)로 선언되어야 한다.</p><h3>7. 스위프트에서 self 사용</h3><p>현재의 클래스 인스턴스에 속한 메서드나 프로퍼티를 가리킬 때 self를 사용한다.</p><pre>document?.openwithCompletionHandler({(success: Bool) -&gt; Void in<br>	if success {<br>        self.ubiquityURL = resultURL<br>    }<br>})</pre><pre>class MyClass {<br>	<br>    var myNumber = 10<br>    <br>    func addTen (myNumber: Int) {<br>    	print(myNumber)<br>        print(self.myNumber)<br>    }<br>}</pre><p>프로퍼티나 메서드를 클로저 표현식 내에서 참조할경우, 함수의 매개변수가 클래스 프로퍼티와 동일한 이름을 가질 경우에 주로 self를 사용한다.</p><h3>8. 스위프트 프로토콜</h3><p>클래스가 충족해야 하는 최소한의 요구사항을 정의하는 규칙들의 집합을 프로토콜이라고 한다. 프로토콜은 protocol 키워드를 이용하여 선언되며 클래스가 반드시 포함해야 하는 메서드와 프로퍼티를 정의한다. 어떤 클래스가 프로토콜을 채택했으나 모든 프로토콜의 요구사항을 충족하지 않는다면, 그 클래스가 해당 프로토콜을 따르지 않는다는 에러가 발생한다.</p><pre>protocol MessageBuilder {<br>	<br>    var name: String { get }<br>    func buildMessage() -&gt; String<br>}</pre><pre>class MyClass: MessageBuilder {</pre><pre>var name: String<br>    <br>    init(name: String) {<br>    	self.name = name<br>    }<br>    <br>    func buildMessage() -&gt; String {<br>    	&quot;Hello &quot; + name<br>    }<br>}</pre><h3>9. 불투명 반환 타입</h3><p>특정 반환 타입을 지정하는 대신, 불투명 반환 유형을 사용하면 지정된 프로토콜을 따르는 모든 타입이 반환될 수 있게 한다. 불투명 반환 타입을 가진 함수, 메서드는 자신의 반환타입 정보를 외부에 숨길 수 있다. 프로토콜 이름 앞에 some 키워드를 붙여 선언된다.</p><pre>func doubleFunc1(value: Int) -&gt; some Equatable {<br>	value * 2<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20ecebae7693" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gdsc-tuk/ios%EC%8A%A4%ED%84%B0%EB%94%94-3%EC%A3%BC%EC%B0%A8-ch10-20ecebae7693">iOS스터디 3주차 Ch10</a> was originally published in <a href="https://medium.com/gdsc-tuk">GDSC TUK</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>