This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let input = 10.52834213 | |
| // x-> 몇째 자리인지 구하는 변수 | |
| x = 10^3 // 10의 3승 -> 1000 만약 2째 자리라면 10의 2승을 넣는다. | |
| let roundedNum = round(input * x) / x | |
| //결과 : 10.528 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //url에 정확한 이미지 url 주소를 넣는다. | |
| let url = URL(string: image.url) | |
| var image : UIImage? | |
| //DispatchQueue를 쓰는 이유 -> 이미지가 클 경우 이미지를 다운로드 받기 까지 잠깐의 멈춤이 생길수 있다. (이유 : 싱글 쓰레드로 작동되기때문에) | |
| //DispatchQueue를 쓰면 멀티 쓰레드로 이미지가 클경우에도 멈춤이 생기지 않는다. | |
| DispatchQueue.global().async { | |
| let data = try? Data(contentsOf: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch | |
| DispatchQueue.main.async { | |
| image = UIImage(data: data!) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let t = 8 | |
| //1 <= value && value <= 10 처럼 써도 되지만 밑의 코드가 훨씬 더 간결하게 보인다. | |
| if case (1...10) = t { | |
| print("t is between 1 and 10") | |
| } | |
| //case를 쓰기 싫다면 ~을 넣어줘도 좋다. | |
| if (1...10) ~= t { | |
| print("t is between 1 and 10") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let str = " Taylor Swift " | |
| let trimmed = str.trimmingCharacters(in: .whitespacesAndNewlines) | |
| 결과 "Taylor Swift”. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension CALayer { | |
| func addBorder(_ arr_edge: [UIRectEdge], color: UIColor, width: CGFloat) { | |
| for edge in arr_edge { | |
| let border = CALayer() | |
| switch edge { | |
| case UIRectEdge.top: | |
| border.frame = CGRect.init(x: 0, y: 0, width: frame.width, height: width) | |
| break | |
| case UIRectEdge.bottom: | |
| border.frame = CGRect.init(x: 0, y: frame.height - width, width: frame.width, height: width) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lazy var stackView: UIStackView = { | |
| //arrangedSubviews <- 안에 있는 값은 클래스에서 불러온값 | |
| let stackV = UIStackView(arrangedSubviews: [stackviewF.view1, stackviewF.view2, stackviewF.view3]) | |
| stackV.translatesAutoresizingMaskIntoConstraints = false | |
| stackV.axis = .horizontal | |
| stackV.spacing = 10 | |
| stackV.distribution = .fillEqually | |
| return stackV |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let parameters : Parameters = ["id" : "아이디","password" : "비밀번호"] | |
| // json에서 key값 설정 | |
| struct userlist: Codable { | |
| var email : String | |
| var result : String | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIViewController { | |
| func showToast(message : String, font: UIFont) { | |
| let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 75, y: self.view.frame.size.height-100, width: 150, height: 35)) | |
| toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6) | |
| toastLabel.textColor = UIColor.white | |
| toastLabel.font = font | |
| toastLabel.textAlignment = .center; | |
| toastLabel.text = message |
OlderNewer