Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- UITableView
- UIView
- 보라카이
- 해몽
- 포켓몬 GO
- Bitcode
- 포켓볼
- LG유플러스
- 샘플
- Example
- 아이폰7
- 신도림 테크노마트
- setting
- afterdelay
- simulator
- swift3
- 신도림
- error
- 공략
- loop
- 페이백
- Xcode
- swift
- 앱스토어
- IOS
- Check
- 스마트폰
- push
- 얻는법
- GCD
Archives
- Today
- Total
도래울
Loop through subview to check for empty UITextField - Swift 본문
for view in self.view.subviews as! [UIView] {
if let textField = view as? UITextField {
if textField.text == "" {
// show error
return
}
}
}See "Downcasting" in the Swift book.
Update for Swift 2: As of Swift 2/Xcode 7 this can be simplified.
- Due to the Objective-C "lightweight generics",
self.view.subviewsis already declared as[UIView]in Swift, therefore the cast is not necessary anymore. - Enumeration and optional cast can be combined with to a for-loop with a case-pattern.
This gives:
for case let textField as UITextField in self.view.subviews {
if textField.text == "" {
// show error
return
}
}'개발 > iOS' 카테고리의 다른 글
| ios get the previous viewcontroller that pushed my current view (0) | 2016.07.15 |
|---|---|
| swift Get button click inside UI table view cell (0) | 2016.07.13 |
| remove all subviews of a view in Swift (0) | 2016.07.13 |
| swift for in loop (0) | 2016.07.13 |
| swift uitableview checkbox example (0) | 2016.07.13 |
Comments