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:
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
- }
VI: NSAutoreleasePool realization
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = uiapplicationmain (argc, argv, nil, nil); [Pool release]; return RetVal;
Seven: About lazy loading:
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 }
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:
- if (ios8_or_later) {//Determine if it is IOS8
- [[UIApplication sharedapplication] SetStatusBarStyle:UIStatusBarStyleLightContentanimated:NO];
- }
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.)