Summarize several common codes developed by IOS

Source: Internet
Author: User

I have summarized some common IOS code recently.

1. variable parameters in IOS

It is common in nsarray initialization methods, such:

@interface NSArray (NSArrayCreation)+ (id)arrayWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION;- (id)initWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION;//...@end

Ns_requires_nil_termination is a macro used for non-Nil end check during compilation. The method for customizing indefinite parameters is the same as that for C/C ++. The example is as follows:

- (id)initWithColumns: (NSString*)firstColumnName, ... {if (self = [self init]) {NSMutableArray* arrays = [NSMutableArray array];va_list argList;if (firstColumnName) {[arrays addObject:firstColumnName];va_start(argList, firstColumnName);id arg;while ((arg = va_arg(argList, id))) {[arrays addObject:arg];}}self.columnNames = [NSArray arrayWithArray:arrays];}return self;}

2. url encoding in IOS

Nsstring * escapedurlstring = [encoding: nsutf8stringencoding] Or nsstring * encodedstring = (nsstring *) encoding (null, (cfstringref) yourtext, null, (cfstringref )@"! * '();: @ & = + $ ,/? % # [] ", Kcfstringencodingutf8 );

3. Determine whether the iOS device is an iPad.

#define IS_IPAD ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

 

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.