티스토리 뷰

iOS(swift)

자주 사용할 코드

광그로 2017. 11. 2. 12:51

자주 사용하는 코드

  • (String).NilOrEmpty()

    public extension String {
       func trim() -> String {
           return self.trimmingCharacters(in: CharacterSet.whitespaces)
       }
       func NilOrEmpty()->Bool{
           if(self.trim().isEmpty){return true}
           else{return false}
       }
    }
  • 숫자만 가능한 TextField

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
           if(textField == ageTextField){
               let allowedCharacters = CharacterSet.decimalDigits
               let characterSet = CharacterSet(charactersIn: string)
               return allowedCharacters.isSuperset(of: characterSet)
           }
           return true
    }
  • Storyboard Navigate to next ViewController

    let storyBoard = UIStoryboard(name: "Main", bundle: nil)
           
    guard let nextViewController = storyBoard.instantiateViewController(withIdentifier: NextViewController.reuseIdentifier) as? NextViewController else{return}
           
    present(thirdViewController, animated: true, completion: nil)
  • ReuseIdentifier

    extension NSObject{
       static var reuseIdentifier: String{
           return String(describing: self)
       }
    }
  • UnwindSegue

    //돌아가야할 ViewController에 기입
    @IBAction func unwindViewController(segue:UIStoryboardSegue){}
    //Action을 수행하는 ViewController
    self.performSegue(withIdentifier: "unwindIdentifier", sender: nil)
  • Random

    let Max:UInt32 = 9
    let Min:UInt32 = 1
    let random = Int(arc4random_uniform(Max) + Min)


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
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
글 보관함