iOS development--Kinky skills Summary of various sexual techniques in the development of &ios (IV.)

Source: Internet
Author: User

Summary of various kinky techniques in iOS development (iv)


One: @autoclosure a block of code alive an expression is automatically encapsulated into a closure
Func logiftrue (predicate: ()-Bool) {  if  predicate () {            print ("True " )       

Call

    • Logiftrue ({return 2 > 1}) shorthand: logiftrue{2 > 1}

You can omit {} directly using Logiftrue (2>1) when predicate plus @autoclosure call.





Two:?? Definition of:
    • Func?? <T> (Optional:t, @autoclosure defaultvalue: () T?)


Three: Closures:
    • ({(), () in
    • })


Four: operator overloading:
    • Func + (left:vector2d, right:vector2d), vector2d {return vector2d (x:left.x + right.x, Y:left.y + right.y)

Five: Error- Operator implementation without matching Operator declaration

Because the operator is not declared

    • Infix operator +* {associativity None precedence 160

    • Infix

    • Associativity
    • Precedence

VI: NSAutoreleasePool realization

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];     int retVal = uiapplicationmain (argc, argv, nil, nil);    [Pool release];     return RetVal;

Seven: About lazy loading:

    • Oc
  1  @property (nonatomic, strong) Nsarray * DataArray;    3  //   override get method   4 -(Nsarray *) DataArray   5  {  6  if  (nil == _dataarray) {  7  _dataarray = [Nsarray array];   "   9  return   _dataarray  10 } 
    • Swift

You can do it so easily.

1 // 1. Analysis Nsarray is a closure of the return value, and this is a closed packet without parameters 2     Lazy var Dataarray:nsarray = {3         return  []4    } () 5 6     // 2. It can also be written like this 7     Lazy var Dataarray:nsarray = {8         return  nsarray ()9     }()

But that's how we usually load some data.

1 //3. Loading from the plist file2Lazy var dataarray:array<xwwine> = {3Let Winepath = Nsbundle.mainbundle (). Pathforresource ("wine.plist", Oftype:nil)!4 5Let Winesm =Nsmutablearray (contentsoffile:winepath);6 7var tmparray:array<xwwine>! = []8 9              forTmpwinedictinchwinesm! {Ten  Onevar wine:xwwine = xwwine.winewithdict (tmpwinedict as!nsdictionary) A  - tmparray.append (wine) -             } the  -Print"I run it one time") -  -             returnTmparray +}()
Eight: Set the status bar style
    • First step: Add a field to Info.plist: View controller-base status bar set to No
    • Step two: Add in a parent class where all interfaces inherit:
    1. if (ios8_or_later) {//Determine if it is IOS8
    2. [[UIApplication sharedapplication] SetStatusBarStyle:UIStatusBarStyleLightContentanimated:NO];
    3. }
Nine: Practical KVC way to modify the properties of the inner placeholer of the text box (Uitextfield) (we'll talk about using a custom Uitextview later)
@" username is in here! " ;  [TextField Setvalue:[uicolor Redcolor] Forkeypath: @" _placeholderlabel.textcolor " ];  [TextField setvalue:[uifont boldsystemfontofsize:+] Forkeypath:@ "_ Placeholderlabel.font"];  
This is the way to use the KVC, isn't it very simple? Oh!

iOS development--Kinky skills Summary of various sexual techniques in the development of &ios (IV.)

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.