九月第三周
1.Swift 可选代理实现:
@objc protocol MainCommentBtnDelegate : NSObjectProtocol{
/** 点击btn 通过代理传值 - parameter index: btn的位置 - parameter commentText: 评论的内容 - parameter isShoucang: 收藏 0:代表未收藏 1:代表收藏 */
optional func mainCommentBtn(index :Int, commentText: String, isShoucang:String)
}
2.Swift设置“#if/#else/#endif”:
#if PREORDER
configData()
#endif
https://www.cnblogs.com/Bob-wei/p/5237761.html
[图片上传失败...(image-ad73b1-1537005769874)]
3.swift @discardableResult 声明:
我好像一直使用通配符_处理的。
https://blog.csdn.net/zx416632112/article/details/79015608
4.判断textField输入五位长度:
func isPreorderCodeOverlength() -> Bool {
let replacedRange = textField.selectedTextRange ?? UITextRange()
let replacedLength = textField.offset(from: replacedRange.start, to: replacedRange.end)
let overlength = textField.text!.count - replacedLength + 1 > 5
return overlength
}
func isPreorderCodeValid() -> Bool {
let lengthValid = textField.text!.count == preorderCodeLength
let contentValid = !textField.text!.contains { Int(String($0)) == nil }
return lengthValid && contentValid
}
5.取得error的code码:
Error没有cod字段,NSError存在code字段
6.报错信息Xib Fatal error: Unexpectedly found nil while unwrapping an Optional value:
原因:跳转前VC 还没初始化完,这个和OC不一样。
fileprivate func presentToCheckWithWaiterViewController(){
let controller = CheckBillWithWaiterController()
present(controller, animated: false, completion: nil)
controller.configureUI(topText: "本功能暂时无法提供", bottomText: "请联系服务员结账")
}
网友评论