본문 바로가기

iOS

(28)
[Swift] Firebase data read 아래와 같이 realtime database 설정한 후 라벨에 표현해 보았다. var ref: DatabaseReference! @IBOutlet var firstData: UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. ref = Database.database().reference() ref.child("firstData").observeSingleEvent(of: .value) {snapshot in print("---> \(snapshot)") let value = snapshot.value as? String ?? "" DispatchQueue.ma..
개발자 등록. 가격은 12만 9천원. 애플계정이 있다면 http://developer.apple.com/ 에서 account 페이지로 들어가 차근차근 진행하면 된다. 개발때는 굳이 등록할 필요는 없지만, app store 에 앱을 게시하고 싶다면 등록을 해야한다. 개인적인 앱을 게시해보고자 등록을 진행하였다. 리뷰가 진행중이지만 원할하게 게시될지는 모르겠다.
[Swift] dequeueReusableCell 테이블 뷰에서 셀을 추가할때 사용하는 함수. 다만 메모리 절약을 위해 스크롤 등으로 화면이 옮겨질때, 이전에 사용되었던 셀이 재사용된다. 그런대 여기서 문제 하나가 재사용되는 셀을 제대로 초기화를 해주지 않는다면 화면이 옮겨지고 난 이후에 버튼등이 제대로 표현되지 않는다. 따라서 셀 내부에 버튼 등 이벤트들은 따로 데이터를 저장해 줄 필요가 있고, 그 데이터를 활용하여 항상 초기화를 해주어야한다. //Table View guard let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCellCharacteristic", for: indexPath) as? CharacteristicTableViewCell else { return UITab..
[Swift] 함수(Function)? 함수 - 아래 func doSomething(parameters) -> ReturnType { print("Test1") return ReturnType } 메서드 - 아래 class TempClass { func doSomething() { print("test2") } } 1. Closure Closure Named Closure(함수) Unnamed Closure(클로저)
[Swift] contentView Declaration var contentView: UIView { get } Discussion The content view of a UITableViewCell object is the default superview for content that the cell displays. If you want to customize cells by simply adding additional views, you should add them to the content view so they position appropriately as the cell transitions in to and out of editing mode. 셀에다가 무언가를 구현할 때, 최상단부터 최하단까지 잘 이어줘야함... 안그러면...
[Swift] isUserInteractionEnabled 확장 테이블 뷰에서 처음 확장때는 버튼이 눌리질 않고 다음 확장때부터는 정상적으로 눌린다. 스탠다드 타입의 테이블뷰에서는 버튼이 동작이 안될 것이다. 그래서 찾아봤더니 아래와 같이 설정해주니 버튼이 정상 동작한다. cell.contentView.isUserInteractionEnabled = false 유저의 이벤트가 event queue로부터 무시되고 삭제됐는지를 판단하는 boolean 값 만약 isUserInteractionEnabled == false를 하면 view를 위한 touch, press, keyboard 그리고 focus event는 event queue에서 무시되고 삭제된다. 반대로 isUserInteractionEnabled == true를 하게 된다면 event는 정상적으로 뷰에 전..
[Swift] NotificationCenter 데이터를 보내는 방법 여러가지가 있지만 아래가 가장 간단했다. 특히 pop up 을 띄울 경우, 이전 뷰컨으로 보낼때 유용했다. //button section NotificationCenter.default.post(name: .writeCharacteristic, object: self.savedTextField) //initial section(viewDidLoad) NotificationCenter.default.addObserver(self, selector: #selector(writeCharacteristic), name: .writeCharacteristic, object: nil) //received data section @objc func writeCharacteristic(_ noti..
[Swift] Substring 만약 text를 자를 일이 있다면 아래와같이 코드블럭 추가해 주는게 편하다. extension String { func substring(from: Int, to: Int) -> String { guard from = 0, to - from >= 0 else { return "" } // Index 값 획득 let startIndex = index(self.startIndex, offsetBy: from) let endIndex = index(self.startIndex, offsetBy: to + 1) // '+1'이 있는 이유: endIndex는 문자열의 마지막 그 다음을 가리키기 때문 // 파싱 return String(self[startIndex ..< endIndex]) ..