Swift Code Summary 4

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.