반응형

개발자 코드(Code) 37

IOS) 홀수 / 짝수 판별 (TextField, Button, Label)

// // ViewController.swift // EvenOdd // // Created by Leo_Jang on 24/08/2020. // Copyright © 2020 Leo_Jang. All rights reserved. // import UIKit class ViewController: UIViewController { @IBOutlet weak var txtNumber: UITextField! @IBOutlet weak var lbltxt: UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @IBAction func btnDiscriminat..

IOS) Hybrid (웹페이지, html, File)

// // ViewController.swift // Hybrid // // Created by Leo_Jang on 26/08/2020. // Copyright © 2020 Leo_Jang. All rights reserved. // import UIKit import WebKit // ****** 반드시 먼저 import WebKit 을 시켜준다. class ViewController: UIViewController { @IBOutlet weak var txtUrl: UITextField! @IBOutlet weak var myWebView: WKWebView! @IBOutlet weak var myActivityIndicator: UIActivityIndicatorView! // 웹페이지 불러주는 ..

IOS) 버튼 클릭시 텍스트 번갈아보기

// // ViewController.swift // HelloWorld // // Created by Leo_Jang on 24/08/2020. // Copyright © 2020 Leo_Jang. All rights reserved. // import UIKit class ViewController: UIViewController { @IBOutlet weak var lblText: UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @IBAction func btnSwitch(_ sender: UIButton) { switch lblText.text{ ..

Swift) 13_Closure

import Cocoa // Closure // first-citizen(일급 시민) // 변수, 상수 등으로 저장, 전달인자로 전달이 가능 // 함수는 이름이 있는 Closure다 // 함수보다 먼저 만들어진 것 // 써도 되고 안써도 되는 것 // 파이썬의 Lambda 함수와 비슷하다. // alert 띄울 때 무조건 써야하는 것 // 기능이 있는 변수 // ----------------------------- // Closure와 함수의 비교 // ----------------------------- // 함수 func sumFunction(a: Int, b: Int) -> Int{ return(a + b) } var sumResult: Int = sumFunction(a: 50, b: 20) pr..

Swift) 11_클래스

import Cocoa //Class // 구조체 타입을 정하는 것이다. class Sample { var sampleProperty: Int = 10 // 가변 Property let fixedSampleProperty: Int = 100 // 불편 Property static var typeProperty: Int = 1000 // 타입 Property func instanceMethod() { print("instance method") } //타입 메서드 // 재정의 불가 타입 메서드 - static static func typeMethod() { print("type method-static") } // 재정의 기능 타입 메서드 - class class func classmethod(){ pri..

Swift) 10_Struct

import Cocoa // 10_ Struct // 구조체 // 구조체는 Swift에서 Type을 정의한다. // kotlin은 Struct구조이다. // 2020. 구글스토어 70% 코틀린이다. // Property & Method struct Sample { var sampleProperty: Int = 10 // 가변 Property let fixedSampleProperty: Int = 100 // 불편 Property static var typeProperty: Int = 1000 // 타입 Property func instanceMethod() { print("instance method") } static func typeMethod(){ print("type method") } } // ..

Swift) 09_값타입과 참조타입

import Cocoa // 09_ 값타입과 참조타입 p.20 /* @ Class - 전통적인 OOP 관점에서의 클래스 - 단일 상속 - 메소드 - 프로퍼티 - 참조타입 @ @ Struct (스위프트는 Struct언어이다.) - 다양한 형태로 사용 가능 - 상속 불가 - 메소드 - 프로퍼티 - 값 타입 - 구조체의 사용 시기 - 연관된 값들을 모아서 하나의 데이터 타입으로 선언하고 싶을 때 - 다른 객체 또는 함수등으로 전달 될 때 - 참조가 아닌 복사를 원할 때 - 자신을 상속할 필요가 없거나 상속 받을 필요가 없을 때 @ Enum (열거형) - 상속 불가 - 메소드 - 프로퍼티 - 값 타입 - 유사한 종류의 여러 값을 유의미한 이름으로 한 곳에 모아 정리 @ Value와 Reference 차이 - V..

Swift) 08_옵셔널.Playground

import Cocoa // Optional // - 값이 있을 수도 있고, 없으 수도 있음 // - nil을 포함 할 수도 있고, 아닐 수 도 있다. var constantNum = 100 //constantNum = nil // let optionalConstant : Int! = nil // 가져올 때 ! 쓴다. let optionalConstant2: Int? = nil // 선언할 때 ? 쓴다. // Optaional 계산 1 var constantNum1: Int? = 100 print(constantNum1! + 10) // Nil 값에 더하기는 안된다. constantNum1 = nil //print(constantNum1! +1) // Nil값 switch로 확인 방법 // 데이터 있을 ..

Swift) 07_반복문.Playground

import Cocoa // ----------------------------------------------------------------------- // let names = ["Anna","Alex","Brian","Jack"] for name in names{ print("Hello, \(name)!") } for (index, text) in names.enumerated(){ print("The name at index \(index) is \(text)") } // 얼마만큼 증가하는가? 0 부터 60까지 5만큼 증가한다. let minutes = 60 let minuteInterval = 5 for tickMark in stride(from: 0, to: minutes, by: minu..

반응형