Online collection and self-summarizing iOS development tips

Source: Internet
Author: User
Tags echo display uikit

Objective-c

1. Let Xcode's console support lldb type of printing

What's the use of this?

How to say, I think this is still more useful drops, why the use of Nikki?

Because when the Xcode breakpoint debugging, the console input PO self.view.frame or PO ID type of the time is dead.
Don't believe me? Look like:

Go to the Chase

Open Terminal Input Three command:

1. Touch ~/.lldbinit

2. Echo Display @import UIKit >> ~/.lldbinit

3. Echo Target stop-hook add-o \ "target Stop-hook disable\" >> ~/.lldbinit

Don't have any prompts after the command has been lost? Well, congratulations on your success! Then, the most critical step is that ...

Rerun the project (no need to restart Xcode), see ~ ~

It means success.

So now we continue to enter PO self.view.frame in the console

It worked! If the PO instruction is an ID type, it can also print normally. Does it feel much more convenient? Anyway, I think so. As for any use, look at personal needs. ~~!

How do I delete it?

OK, so the problem comes, I use the command to create, if you do not want to play what to do, Nikki?

In fact, very simple answer, see the first command Touch ~/.lldbinit, is to create a hidden file in the root directory . Lldbinit, and then delete this file is done.
Open terminal and then, in terminal input:? rm ~/.lldbinit command.

2. Use macro definition to detect if block is available!

#define BLOCK_EXEC (block, ...) if (block) {block (__va_args__);};     // previous usage  of macro definition /* if (completionblock)   {       Completionblock (arg1, arg2);   }      */     // use  after a macro definition Block_exec (Completionblock, arg1, arg2);

3. Use @ () to include C strings or non-OC objects

NSString *propertyattributesstring =    class"description")));

4. Use arc and do not use arc (from Summer Summer)

// use arc and do not use arc #if __has_feature (OBJC_ARC)//compiling with arc#else//  compiling Without ARC#endif

5.iOS Image Memory Optimization (blog) memory optimization experience (from gray ash)

Resolution Steps: Instrument debugging, found not to be released is all ImageIO, almost know, the way to read the map, from [UIImage imagenamed:@ "], change to Imagewithcontentsoffile, you can.

Cause: Imagenamed the way to read pictures, will be cached in memory, so the larger picture, or with Imagewithcontentsoffile.

The picture in the tip1:.xcassets cannot be read with Imagewithcontentsoffile;

Tip2:imagewithcontentsoffile read pictures need to add file suffix name such as png,jpg, etc.;

6. Print the controller hierarchy in the console

Use the PO [uiviewcontroller _printhierarchy] command in the console to print out the controller's hierarchy at a glance. Let's all go play. ~~1

7. Print the View hierarchy in the console

Use the PO [[[[UIApplication sharedapplication] keywindow] command in the console to print out the view level at a glance.

Of course, it might be confusing for some people to print all the view levels under window.

However, you can also print a hierarchy that specifies a view.

PO [view Recursivedescription]

8. print the properties and values of the object using the PO command in the console in debug mode

Add categories, plus code. Without importing the header file, you can print out the model's properties and values in the console using the PO command, which mainly uses the method of deception and replaces the description method of the system.

9. Create a single case with a macro

#define Synthesize_singleton_for_class_arc (className) \+ (className *static className *shared## ClassName =static  dispatch_once_t Oncetoken; dispatch_once (&oncetoken, ^=  return  shared# #className;}

10. Determine if the system is greater than, less than, equal to a version

#define System_version_less_than (v) ([[[                 Uidevice Currentdevice] systemversion] compare:v options:nsnumericsearch] = = nsorderedascending)#define system_version_less_than_or_equal_to (v) ([[[     Uidevice Currentdevice] Systemversion] Compare:v options:nsnumericsearch]! = nsordereddescending)#define System_version_greater_ Than_or_equal_to (v) ([[[  [Uidevice Currentdevice] systemversion] compare:v options:nsnumericsearch]! = nsorderedascending)

11. Weak references and strong reference macros

#define Strongself ()  __strong typeof (weakself) strongself = weakself#define weakself () __weak __typeof (&* Self) weakself = self

In a custom block, the weak reference is then strongly quoted to prevent it from being released.

weakself ();     = ^(nsuinteger index, Nsuinteger seledrow)    {        strongself ();        [Strongself.tableview reloaddata];    };

However, one thing to note is that the system block does not require a weak reference, for reasons please refer to https://www.zhihu.com/question/36358590

12. How to hide the divider line below the navigation bar

  [Self.navigationController.navigationBar setbackgroundimage:[uiimage imagewithcolor:[uicolor Whitecolor] ] Forbarmetrics:uibarmetricsdefault];   New];
+ (UIImage *) Imagewithcolor: (Uicolor *) color{    cgrect rect=cgrectmake (0.0f0.0f  1.0f1.0f);    Uigraphicsbeginimagecontext (rect.size);     = Uigraphicsgetcurrentcontext ();    Cgcontextsetfillcolorwithcolor (context, [color Cgcolor]);    Cgcontextfillrect (context, rect);         *theimage = uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext ();     return theimage;}

13. Monitor network status

[[Afnetworkreachabilitymanager Sharedmanager] startmonitoring]; //A single case for detecting network connections and a callback method for network changes[[Afnetworkreachabilitymanager Sharedmanager] setreachabilitystatuschangeblock:^(afnetworkreachabilitystatus status) {Ddloginfo (@"%ld", (Long) status); NSString*NetName; Switch(status) { CaseAfnetworkreachabilitystatusunknown:netname=@"Unknown";  Break;  CaseAfnetworkreachabilitystatusnotreachable:netname=@"No network";  Break;  CaseAfnetworkreachabilitystatusreachableviawwan:netname=@"3G";  Break;  CaseAfnetworkreachabilitystatusreachableviawifi:netname=@"WiFi";  Break; default:                 Break; }    }];

14. How to quickly set up BorderWidth, BorderColor, Cornerradius, masktobounds in Xib

. h file

#import <UIKit/UIKit.h>@interface*bx_bordercolor; @property (Nonatomic, Assign) ibinspectable cgfloat Bx_cornerradius; @property (nonatomic, assign) ibinspectable BOOL bx_masktobounds; @end

. m file

#import<objc/runtime.h>@implementationUIView (layeradditions)- (void) Setbx_bordercolor: (Uicolor *) bx_bordercolor{objc_setassociatedobject (self, @selector (bx_bordercolor), Bx_bordercolor, Objc_association_    Retain_nonatomic); Self.layer.borderColor=Bx_bordercolor.cgcolor;}-(Uicolor *) bx_bordercolor{returnObjc_getassociatedobject (self, _cmd);}- (void) Setbx_borderwidth: (cgfloat) bx_borderwidth{objc_setassociatedobject (self, @selector (bx_borderwidth), @ (bx_    borderWidth), objc_association_retain_nonatomic); Self.layer.borderWidth=bx_borderwidth;}-(cgfloat) bx_borderwidth{return[Objc_getassociatedobject (Self, _cmd) floatvalue];}- (void) Setbx_cornerradius: (cgfloat) bx_cornerradius{objc_setassociatedobject (self, @selector (Bx_cornerradius), @ (BX    _cornerradius), objc_association_retain_nonatomic); Self.layer.cornerRadius=Bx_cornerradius;}-(cgfloat) bx_cornerradius{return[Objc_getassociatedobject (Self, _cmd) floatvalue];}- (void) Setbx_masktobounds: (BOOL) bx_masktobounds{objc_setassociatedobject (self, @selector (bx_masktobounds), @ (bx_    masktobounds), objc_association_retain_nonatomic); Self.layer.masksToBounds=bx_masktobounds;}-(BOOL) bx_masktobounds{return[Objc_getassociatedobject (Self, _cmd) boolvalue];}@end

Online collection and self-summarizing iOS development tips

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.