1.swift @discardableResult Statement:
Swift Normal method If there is a return value, the call must have a receiver, otherwise the compiler will report a warning,
If you add @discardableResult to the method before you do not handle it, there will be no warning. You can also use a wildcard to receive the method return value, you can achieve the same purpose.
2. Controller initialization:
Init (urlstr:string?) { Super.init (Nibname:nil, Bundle:nil) if let Urlstr = urlstr { = urlstr }< C10/>}uiview initialization: Calling the parent class initWithFrame
3. Update the View constraint:
/// Update level Two menu constraints Private func updatesecondcategorylayout () { if let Tempheight = Height { Secondcategoryview.needsupdateconstraints () 0.25) { self.secondCategoryView.layoutIfNeeded () }}}
4. Pull up load more:
In else{return} if self.pagenum <= self.totalpage { self.loaddata () Else { self.printTable.mj_ Footer.endrefreshing () self.printTable.mj_footer.endRefreshingWithNoMoreData () } )
5.uiview.performwithoutanimation:
uiview.performwithoutanimation { plandiscountcollectionview.reloadsections (indexset (integer: Indexset.element (0)) }// View conversion does not perform animations, parameters are block objects, to execute the code you want to execute + ( void) Performwithoutanimation: (void (^) (void)) actionswithoutanimation
6. Decimal conversion:
if temptextcount.decimalvalue > Nsdecimalnumber (string: WaiterManager.shared.waiterPower ( Powercode.ignore)? . Powervalue). Decimalvalue {}
7. Limit TextField to enter only 3 characters:
string: String), Bool { 0 string. Count- Range.length return 3 }
8. Variable security using the Set method private, you can adjust the method to change the value:
class hhtcomboglobaldata:nsobject { static let shared = hhtcomboglobaldata () Private(setvar combomodes:[combomodel] = [] func Setcombomodel (with dicts:[ Jsondictionary]) { combomodes.removeall () in return Combomodel ( with:dict) }}}
9.for Loop create nine lattice:
Privatefunc setupui () {Let count:int=5Let width:cgfloat= -Let height:cgfloat= -Let bgviewwidth:cgfloat=844Let col:int=3 //spacingLet Hmargin = (Bgviewwidth-(CGFloat (COL) * width)/cgfloat ((col+1)) Let Vmargin:cgfloat= - varRow:int =0 forIinch 0.. <Count {let Button:uibutton=UIButton () button.settitle ("Print a", for:. Normal) Button.settitlecolor (Uicolor.white, for:. Normal) Button.backgroundcolor=uicolor.redifI%col = =0{row+=1 } varY:cgfloat =0 ifrow = =1{y= - } Else{y= Vmargin + (height + vmargin) *cgfloat (Row)} Let X:cgfloat= Hmargin + (width + hmargin) * CGFloat (i%col) Button.frame=CGRect (x:x, Y:y, Width:width, Height:height) Bgview.addsubview (button) BottomMargin= Button.frame.maxY + -} bgheightconstraint.constant= bottommargin! }}
Swift Code Summary 4