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)