일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 2차원 객체배열
- Gradle
- Xcode
- 사용법
- switch-case
- 클래스
- SWiFT
- class
- guard
- PHP
- DatePicker
- CodeIgniter
- 옵셔널
- Java
- Spring
- 전의 의존성
- 차이점
- CKEditor4
- pagination
- 자료불러오기
- AWS
- 함수
- amazon
- 제어문
- jQuery
- bootstrap
- 상속
- programmers
- 객체
- EC2
Archives
- Today
- Total
not bad 한 개발
Swift - Xcode를 활용하여 간단한 앱 만들기 본문
(인덕대학교 컴퓨터소프트웨어학과 iOS 프로그래밍 기초(21-2학기) 한성현 교수님 강의 내용을 변형 및 요약했습니다.)
Xcode
- Xcode는 mac에서 swift를 사용하여 앱을 만드는 도구입니다.
- Xcode를 잘 사용할 줄 안다면 Android Studio에서 안드로이드 앱을 만드는 데에도 도움이 됩니다.
- UI를 drag & drop 하여 UI를 디자인하고 그 후 본인이 원하는 방향대로 코딩하는 방식입니다.
- 프로젝트를 만들면 기본적으로 앱을 구동할 수 있는 틀을 만들어 줍니다.
(이번에는 간단히 Button, Label, TextField만 사용하여 앱을 만들어봤습니다.)
AppDelegate.swift (프로젝트 생성 시 기본으로 만들어지는 파일이지만 이번 프로젝트에는 수정하지는 않았습니다.)
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
SceneDelegate.swift (프로젝트 생성시 기본으로 만들어지는 파일이지만 이번 프로젝트에는 수정하지는 않았습니다.)
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var ldblabel: UILabel!
@IBOutlet weak var ldbinput: UITextField!
@IBAction func ldbinsert(_ sender: UIButton) {
ldblabel.text = "Hi," + ldbinput.text!
}
@IBAction func ldbdelete(_ sender: UIButton) {
ldblabel.text = "Welcome ! Xcode"
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
(실행결과)
(Welcome ! Xcode가 처음으로 나오고 TextField에 문자를 입력하고 "입력" 버튼을 누르면 Label에 Hi, [입력한 문자] 이렇게 나오고 삭제 버튼을 누르면 Label에 처음 Label과 동일한 "Welcome ! Xcode"가 Label에 입력됩니다.)
'Swift' 카테고리의 다른 글
Swift - Xcode를 활용하여 간단한 앱 만들기 (2) (0) | 2021.11.12 |
---|---|
Swift - enum(열거형) (0) | 2021.11.03 |
Swift - protocol(프로토콜) (0) | 2021.11.03 |
Swift - access modifier(접근 제어) (0) | 2021.11.03 |
Swift - extension(확장) (0) | 2021.11.03 |
Comments