1. Handwriting Bubble and insert sort
bubble sort comes from the common sense of life, the equivalent of putting the array up, light upward, heavy downward.
voidBubblesort (int[] unsorted) { for(inti =0; I < unsorted. Length; i++) { for(intj = i; J < unsorted. Length; J + +) { if(Unsorted[i] >Unsorted[j]) { inttemp =Unsorted[i]; Unsorted[i]=Unsorted[j]; UNSORTED[J]=temp; } } }}
Insert Sort, a bit like a fight when the landlord touch a card with a straight, 345678910JQKA, first pumped to 3, 5 to 4 4 inserted in 3, 5.
voidInsertsort (int*a,intN) { intI,j,key; //control which elements need to be inserted for(i =1; I < n; i++) { //key is the element to be insertedKey =A[i]; //Find where to insert, loop ends, find insertion position for(j = i; j >0&& a[j-1] > key; j--) { //moves the position of the element for the element to be inserted using theA[J] = a[j-1]; } //Insert the element you want to insertA[J] =key; }}
2. Overriding the Setter/getter method
Suppose declaring a property@property (nonatomic, copy) NSString *iMagename; once the Setter,getter method is overridden here, the compiler will not give us the automatic generation of the member variable _imagename, so we need to add a member variable _imagename in the declaration of the class: @interfaceDemo () {NSString *_imagename; } @end
one, in Arc- (void) Setimagename: (NSString *) AName { if(_imagename! =aName) {_imagename =Nil;_imagename =[aName copy]; } }-(NSString *) ImageName { return_imagename; }Second, the MRC
-(void) Setimagename: (NSString *) AName { if (_imagename! = aName) {
[_imagename release]; _imagename = nil; _imagename = [aName copy]; } }-(NSString *) imageName { return _imagename;
3. Handwriting Simple single case
+ (instancetype) shared { static xngusermanager *sg_usermanager = nil; Static dispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{ if (Sg_usermanager = = nil) {= [[Xngusermanager alloc] init]; } ); return Sg_usermanager;}
4. Talk about notifications in iOS
One, get the notification object:
Nsnotificationcenter *center =[Nsnotificationcenter Defaultcenter];
Two, three properties of the notification object @property (ReadOnly, copy) NSString *name;//The name of the notification @property (nullable,ReadOnly, retain)ID Object;//Notification of Publisher @property (nullable,ReadOnly, copy) Nsdictionary *userinfo;//additional information that can store some data three, the initial method of notifying the object
-(Instancetype) Initwithname: (NSString *) nameObject:(NullableID)ObjectuserInfo: (Nullable nsdictionary*) UserInfo;+ (Instancetype) Notificationwithname: (NSString *) ANameObject:(NullableID) AnObject;+ (Instancetype) Notificationwithname: (NSString *) ANameObject:(NullableID) AnObject UserInfo: (Nullable nsdictionary*) Auserinfo;
Iv. three ways to publish notifications- (void) Postnotification: (Nsnotification *) notification;- (void) Postnotificationname: (NSString *) ANameObject:(NullableID) AnObject;- (void) Postnotificationname: (NSString *) ANameObject:(NullableID) AnObject UserInfo: (Nullable nsdictionary*) Auserinfo;
Five, registration notice
- (void) Addobserver: (ID) Observer selector: (SEL) aselector name: (Nullable NSString*) ANameObject:(NullableID) AnObject; - (ID<NSObject>) Addobserverforname: (Nullable NSString *) nameObject:(NullableID) obj queue: (Nullable Nsoperationqueue*) Queue Usingblock: (void(^) (Nsnotification *note)) Block
VI. Cancellation of Registration notice- (void) Removeobserver: (ID) Observer; - (void) Removeobserver: (ID) Observer Name: (Nullable NSString*) ANameObject:(NullableID) AnObject;- (void) Dealloc {[[Nsnotificationcenter defaultcenter] removeobserver:self];}
What is the difference between 5.UIView and Clayer
1). UIView is the basis for interface elements in IOS systems, and all interface elements are inherited from it. It is entirely by coreanimation to achieve it.
The real drawing part of it is managed by a Calayer class. UIView itself is more like a Calayer manager, accessing its properties related to drawing and coordinates. 2). UIView has an important attribute layer that can return its primary calayer instance. 3). UIView's calayer is similar to UIView's sub-View tree structure, or it can add a sub layer to its layer to accomplish some special representations.
That is, the Calayer layer can be nested. 4). The UIView layer tree is inside the system and is maintained with three copies. Is the logical tree, here is the code can be manipulated;
The animation tree, which is a middle layer, changes properties on this layer, makes various rendering operations, and displays a tree whose content is what is currently being displayed on the screen. 5). The animation works: changes are made to UIView's sublayer (non-primary Layer) property, the system automatically animates, and the default value for the duration of the animation appears to be0.5seconds. 6). Coordinate system: Calayer's coordinate system is more than UIView a Anchorpoint property, using the Cgpoint structure, the range is0~1, which is a proportional value.
This point is the coordinate origin of the various graphic transformations and changes the position of the layer's position, whose default value is {0.5,0.5}, which is in the center of the layer. 7). Render: When updating the layer, changes cannot be displayed immediately on the screen. When all the layers are ready, you can call the Setneedsdisplay method to redraw the display. 8). Transform: To add a 3D or affine transformation to a layer, you can set the transform or AffineTransform properties of the layer, respectively. 9). Deformation: Quartz Core rendering ability, so that the two-dimensional image can be freely manipulated, as if it is three-dimensional.
The image can be rotated, scaled and tilted at any angle in a three-dimensional coordinate system. Catransform3d's set of methods provides some magic-like transitions.
iOS Development engineer Face question (ii)