NSPredicate*myTest=[NSPredicatepredicateWithFormat:@"SELFMATCHES%@",someRegexp];
if([myTestevaluateWithObject:testString]){
//Matches
}
People*p1=[Peoplenew];
p1.firstName=@"12345";
People*p2=[Peoplenew];
p2.firstName=@"123456";
People*p3=[Peoplenew];
p3.firstName=@"123";
NSArray*array=@[p1,p3,p2];
//设置一个模板谓词
NSPredicate*_predicate=[NSPredicatepredicateWithBlock:^BOOL(People*people,NSDictionary*bindings){
return[people.firstNamelength]>[[bindingsvalueForKey:@"length"]intValue];
}];
NSDictionary*bindings=@{@"length":@3};
NSIndexSet*indexSet=[arrayindexesOfObjectsPassingTest:^BOOL(idobj,NSUIntegeridx,BOOL*stop){
return[_predicateevaluateWithObject:objsubstitutionVariables:bindings];
#import"Forwarder.h"
#import
@interfaceMan:NSObject
-(void)method;
@end
@implementationMan
-(void)method{
NSLog(@"forwardingMethod");
@interfaceForwarder()
@property(nonatomic,strong)Man*man;
@implementationForwarder
@dynamicrecipent;
-(void)test{
/*动态方法解析*/
[selfsetRecipent:@"water"];
NSLog(@"%@",self.recipent);
/*消息转发*/
Man*man=[Mannew];
self.man=man;
[selfperformSelector:@selector(method)];
-(void)setRecipent:(NSString*)recipent{
_recipent=recipent;
-(NSString*)recipent{
return_recipent;
+(BOOL)resolveInstanceMethod:(SEL)sel{
if(sel==@selector(setRecipent:)){
Methodmethod=class_getInstanceMethod(self.class,@selector(setRecipent:));
IMPimp=method_getImplementation(method);
class_addMethod([selfclass],sel,imp,method_getTypeEncoding(method));
if(sel==@selector(recipent)){
Methodmethod=class_getInstanceMethod(self.class,@selector(recipent));
return[superresolveInstanceMethod:sel];
/*必须覆盖此方法*/
-(NSMethodSignature*)methodSignatureForSelector:(SEL)aSelector{
return[self.man.classinstanceMethodSignatureForSelector:aSelector];
-(void)forwardInvocation:(NSInvocation*)anInvocation{
SELselector=anInvocation.selector;
if([self.manrespondsToSelector:selector]){
[anInvocationinvokeWithTarget:self.man];
}else{
[selfdoesNotRecognizeSelector:selector];
-(IBAction)downloadButtonPressed:(id)sender{
NSData*date=[selfstartLoadingImage];
UIImage*image=[UIImageimageWithData:date];
self.imageView.image=image;
-(NSData*)startLoadingImage{
__blockBOOLstillDownloading=YES;
__block__strongidresponde=nil;
[NSURLConnectionsendAsynchronousRequest:reqqueue:[NSOperationQueuenew]completionHandler:^(NSURLResponse*resp,NSData*data,NSError*error){
stillDownloading=NO;
responde=data;
intallowTime=30;
NSDate*timeoutDate=[NSDatedateWithTimeIntervalSinceNow:allowTime];
//图片在另一队列中下载,但是当前的线程也不会退出,不同于使用for循环轮询。
CFRunLoopRunInMode(kCFRunLoopDefaultMode,0.01,YES);
if([timeoutDatetimeIntervalSinceNow]<0){//超时报失败
NSLog(@"Failure");
returnresponde;
-(void)waitForTimeout:(NSTimeInterval)timeout{
NSDate*waitEndDate=[NSDatedateWithTimeIntervalSinceNow:timeout];
while([waitEndDatetimeIntervalSinceNow]>0)
{
CFRunLoopRunInMode(kCFRunLoopDefaultMode,kRunLoopSamplingInterval,YES);
-(BOOL)isValidateString:(NSString*)string{
BOOLisExistDigit=[stringrangeOfCharacterFromSet:[NSCharacterSetdecimalDigitCharacterSet]].location!=NSNotFound;
BOOLisExistLetter=[stringrangeOfCharacterFromSet:[NSCharacterSetletterCharacterSet]].location!=NSNotFound;
returnisExistDigit&&isExistLetter;
NSCharacterSet*_NumericOnly=[NSCharacterSetdecimalDigitCharacterSet];
NSCharacterSet*myStringSet=[NSCharacterSetcharacterSetWithCharactersInString:mystring];
if([_NumericOnlyisSupersetOfSet:myStringSet]){
NSLog(@"Stringhasonlynumbers");
[stage2RequestOperationaddDependency:stage1RequestOperation];
[MobileHttpClientsharedHttpClient]enqueueBatchOfHTTPRequestOperations:<#(NSArray*)#>progressBlock:<#^(NSUIntegernumberOfFinishedOperations,NSUIntegertotalNumberOfOperations)progressBlock#>completionBlock:<#^(NSArray*operations)completionBlock#>
CoreData并发基本规则:
1.一个程序中只需要一个NSPersistentStoreCoordinator。你不需要在每个线程单独创建一个。
2.为每个线程中创建单独一个NSManagedObjectContext。
3.不允许在线程之间传递NSManagedObject对象。
4.你应该通过-objectID获取对象ID,然后传递给其他线程。
更多规则:
1.在获得对象ID之前确保对象已保存到存储区。在保存之前,对象只是临时存在于特定的上下文中,所以你不能使用其他线程中访问,因为每个线程使用的上下文是不一样的,参照基本规则2。
2.如果NSManagedObject被多个线程中修改了,当心合并策略。
3.NSManagedObjectContext的mergeChangesFromContextDidSaveNotification对你会有帮助。
BOOLisTemporary=[[managedObjectobjectID]isTemporaryID];
NSNumber*average=[@[@1,@2,@3]valueForKeyPath:@"@avg.self"];//2
NSNumber*salaryOverhead=[anEmployeevalueForKeyPath:@"department.employees.@sum.salary"];
//4,6,1,7,3
NSOrderedSet*orderedSet=[NSOrderedSetorderedSetWithArray:@[@4,@6,@1,@7,@3]];
//7,3,6,4,1
NSSet*set=[NSSetsetWithArray:@[@4,@6,@1,@7,@3]];
NSString*path=[[NSBundlebundleForClass:[SGCViewControllerclass]].resourcePathstringByAppendingPathComponent:@"cde.png"];
[selfreplaceStore:sourceFileURLwithStore:destinationFileURL];
NSFileManager*fileManager=[NSFileManagerdefaultManager];
NSString*documentsPath=
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)firstObject];
NSString*filePath=[documentsPathstringByAppendingPathComponent:@"file.txt"];
BOOLfileExists=[fileManagerfileExistsAtPath:filePath];
递归枚举指定目录内的文件
NSURL*bundleURL=[[NSBundlemainBundle]bundleURL];
NSDirectoryEnumerator*enumerator=[fileManagerenumeratorAtURL:bundleURL
includingPropertiesForKeys:@[NSURLNameKey,NSURLIsDirectoryKey]
options:NSDirectoryEnumerationSkipsHiddenFiles
errorHandler:^BOOL(NSURL*url,NSError*error){
NSLog(@"[Error]%@(%@)",error,url);
returnNO;
NSMutableArray*mutableFileURLs=[NSMutableArrayarray];
for(NSURL*fileURLinenumerator){
NSString*filename;
[fileURLgetResourceValue:&filenameforKey:NSURLNameKeyerror:nil];
NSNumber*isDirectory;
[fileURLgetResourceValue:&isDirectoryforKey:NSURLIsDirectoryKeyerror:nil];
//Skipdirectorieswith'_'prefix,forexample
if([filenamehasPrefix:@"_"]&&[isDirectoryboolValue]){
[enumeratorskipDescendants];
continue;
if(![isDirectoryboolValue]){
[mutableFileURLsaddObject:fileURL];
列出指定目录内的所有文件
NSArray*contents=[fileManagercontentsOfDirectoryAtURL:bundleURL
includingPropertiesForKeys:@[]
error:nil];
NSPredicate*predicate=[NSPredicatepredicateWithFormat:@"pathExtensionENDSWITH'.png'"];
for(NSString*pathin[contentsfilteredArrayUsingPredicate:predicate]){
//Enumerateeach.pngfileindirectory
创建目录
NSString*documentsPath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)firstObject];
NSString*imagesPath=[documentsPathstringByAppendingPathComponent:@"images"];
if(![fileManagerfileExistsAtPath:imagesPath]){
[fileManagercreateDirectoryAtPath:imagesPath
withIntermediateDirectories:NO
attributes:nil
删除指定文件
NSString*filePath=[documentsPathstringByAppendingPathComponent:@"image.png"];
NSError*error=nil;
if(![fileManagerremoveItemAtPath:filePatherror:&error]){
NSLog(@"[Error]%@(%@)",error,filePath);
阻止对PDF文件的删除操作
//对NSFileManager实例设置代理必须初始化一个新的唯一实例,不要使用defaultManger方法生成的实例。
NSFileManager*fileManager=[[NSFileManageralloc]init];
fileManager.delegate=delegate;
for(NSString*filePathincontents){
[fileManagerremoveItemAtPath:filePatherror:nil];
代理实现:
-(BOOL)fileManager:(NSFileManager*)fileManagershouldRemoveItemAtURL:(NSURL*)URL{
return![[[URLlastPathComponent]pathExtension]isEqualToString:@"pdf"];
NSFileManager代理方法包括
-fileManager:shouldMoveItemAtURL:toURL:
-fileManager:shouldCopyItemAtURL:toURL:
-fileManager:shouldRemoveItemAtURL:
-fileManager:shouldLinkItemAtURL:toURL:
NSExpression*expression=[NSExpressionexpressionWithFormat:@"4+5-2**2"];//9–2^2
idvalue=[expressionexpressionValueWithObject:nilcontext:nil];//5
NSLog(@"%@",value);
NSArray*numbers=@[@1,@2,@3,@4,@4,@5,@9,@11];
NSExpression*expression=[NSExpressionexpressionForFunction:@"sum:"arguments:@[[NSExpressionexpressionForConstantValue:numbers]]];
idvalue=[expressionexpressionValueWithObject:nilcontext:nil];//39
//公式1
NSExpression*expr=[NSExpressionexpressionWithFormat:@"2*x+4*y"];
floatresult=[[exprexpressionValueWithObject:@{@"x":@2,@"y":@2}context:nil]floatValue];//12
//公式2
expression=[NSExpressionexpressionWithFormat:@"(%@+%@)**2",@4,@4];
NSNumber*result=[expressionexpressionValueWithObject:nilcontext:nil];//64
[[[UIAlertViewalloc]initWithTitle:err.localizedDescription
message:err.localizedFailureReason
delegate:self
cancelButtonTitle:@"我知道了"
otherButtonTitles:err.localizedRecoverySuggestion,nil]show];
#import
#import"KivaFeed.h"
/**output:
T@"NSString",C,N,V_name
T{LOCATION=ff},N,V_locaiton
T@"NSArray",&,N,V_colors
Ti,N,V_count
Tc,N,V_success
Tc,N,GisSquare,V_square
Td,R,N,V_time
T@"KivaFeed",&,N,V_kivaFeed
T@"NSArray
*/
structLOCATION{
floatlatitude;
floatlongitude;
};
@protocolFirstProtocol@end
@protocolSecondProtocol@end
@interfaceLender:NSObject
@property(nonatomic,copy)NSString*name;
@property(nonatomic,assign)structLOCATIONlocaiton;
@property(nonatomic,retain)NSArray*colors;
@property(nonatomic,assign)NSIntegercount;
@property(nonatomic,assign)BOOLsuccess;
@property(nonatomic,assign,getter=isSquare)BOOLsquare;
@property(nonatomic,assign,readonly)NSTimeIntervaltime;
@property(nonatomic,strong)KivaFeed*kivaFeed;
@property(nonatomic,weak)NSArray
其中+(UIView*)rootView方法返回当前窗口根视图控制器的视图:
+(UIView*)rootView{
UIViewController*topController=[UIApplicationsharedApplication].keyWindow.rootViewController;
while(topController.presentedViewController){
topController=topController.presentedViewController;
returntopController.view;
NSUIntegerx=1;
intr=MAX(0,x-10);
NSLog(@"%d",r);
输出结果为-9。
iOSApplicaiton目录结构图
Bundle目录(myApp.app)
此目录包含了项目中的所有资源。iOS2.1和以后的版本,iTunes不备份该目录。
访问代码:
NSBundle*bundle=[NSBundlemainBundle];
NSString*bundlePath=[bundlebundlePath];
///var/mobile/Applications/2DD71ECB-1027-4197-AAAB-BD00A67727ED/Test.app
NSLog(@"%@",bundlePath);
NSArray*imagePaths=[bundlepathsForResourcesOfType:@"png"inDirectory:@"DemoImages"];
注意到红色文字部分,iOS使用唯一ID代替应用名标识沙盒路径,所以不要使用绝对或相对路径查找目录。
Document目录
使用该目录存放不可再生文件,如sqlite数据库。该目录的数据将被iTunes备份。
目录访问代码:
NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString*docDir=[pathsobjectAtIndex:0];
//Document目录:/var/mobile/Applications/2DD71ECB-1027-4197-AAAB-BD00A67727ED/Documents
NSLog(@"Document目录:%@\n",docDir);
Library目录
该目录不存放用户的数据文件。iOS程序没有权限使用该目录。但你可以通过在该目录创建子目录的方式存放需要备份但不向用户暴露的文件。
paths=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES);
NSString*libDirectory=[pathsobjectAtIndex:0];
//Library目录:/var/mobile/Applications/2DD71ECB-1027-4197-AAAB-BD00A67727ED/Library
NSLog(@"Library目录:%@",libDirectory);
Library/Caches目录
该目录不被iTunes备份。该目录可用于下载内容,存放数据库缓存文件等可再造的数据文件。
paths=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
NSString*cachesDirectory=[pathsobjectAtIndex:0];
//Library/Caches目录:/var/mobile/Applications/2DD71ECB-1027-4197-AAAB-BD00A67727ED/Library/Caches
NSLog(@"Library/Caches目录:%@",cachesDirectory);
Library/Preferences目录
Apple建议不要在该目录创建任何文件。记录NSUserDefault类设值的plist文件存放于此目录。
tmp目录
存放临时文件的目录,任何时候目录内的文件都可被删除。
NSString*tmpDirectory=NSTemporaryDirectory();
//tmp目录:/private/var/mobile/Applications/2DD71ECB-1027-4197-AAAB-BD00A67727ED/tmp/
NSLog(@"tmp目录:%@",tmpDirectory);
它们的主要区别是:stack是有结构的,每个区块按照一定次序存放,可以明确知道每个区块的大小;heap是没有结构的,数据可以任意存放。因此,stack的寻址速度要快于heap。
其他的区别还有,一般来说,每个线程分配一个stack,每个进程分配一个heap,也就是说,stack是线程独占的,heap是线程共用的。此外,stack创建的时候,大小是确定的,数据超过这个大小,就发生stackoverflow错误,而heap的大小是不确定的,需要的话可以不断增加。
publicvoidMethod1()
inti=4;
inty=2;
class1cls1=newclass1();
上面代码的Method1方法,共包含了三个变量:i,y和cls1。其中,i和y的值是整数,内存占用空间是确定的,而且是局部变量,只用在Method1区块之内,不会用于区块之外。cls1也是局部变量,但是类型为指针变量,指向一个对象的实例。指针变量占用的大小是确定的,但是对象实例以目前的信息无法确知所占用的内存空间大小。
这三个变量和一个对象实例在内存中的存放方式如下。
从上图可以看到,i、y和cls1都存放在stack,因为它们占用内存空间都是确定的,而且本身也属于局部变量。但是,cls1指向的对象实例存放在heap,因为它的大小不确定。作为一条规则可以记住,所有的对象都存放在heap。
接下来的问题是,当Method1方法运行结束,会发生什么事?
回答是整个stack被清空,i、y和cls1这三个变量消失,因为它们是局部变量,区块一旦运行结束,就没必要再存在了。而heap之中的那个对象实例继续存在,直到系统的垃圾清理机制(garbagecollector)将这块内存回收。因此,一般来说,内存泄漏都发生在heap,即某些内存空间不再被使用了,却因为种种原因,没有被系统回收。
typedefstructUIEdgeInsets{
CGFloattop,left,bottom,right;
}UIEdgeInsets;
UIEdgeInsets表示内嵌距离结构体。正数值表示将某一矩形边向内推进,负数值表示将某一矩形边向外拉动。
CGRectUIEdgeInsetsInsetRect(CGRectrect,UIEdgeInsetsinsets)
UIEdgeInsetsInsetRect函数的形参包括一个被操作矩形rect以及一个UIEdgeInsets类型的insets。
如下图:将原始矩形左侧边向外拖动20点,下侧边向外拖动30点。则UIEdgeInsets值为(0.0,-20.0,-30.0,0.0)
完整代码:
CGRectbefore=CGRectMake(100.0,100.0,200.0,100.0);
UIEdgeInsetsinsets=UIEdgeInsetsMake(0.0,-20.0,-30,0.0);
CGRectrectPlusAnnotations=UIEdgeInsetsInsetRect(before,insets);
//输出:rectPlusAnnotations={{80,100},{220,130}}
NSLog(@"rectPlusAnnotations=%@",NSStringFromCGRect(rectPlusAnnotations));
voidCGRectDivide(CGRectinRect,CGRect*outSlice,CGRect*outRemainder,CGFloatamount,CGRectEdgeedge);
功能描述:假设你有一块矩形奶油蛋糕,你现在需要切下一块分给到你家做客的小伙伴。inRect表示将被切分的蛋糕矩形。outSlice表示被切下的蛋糕矩形。outRemainder表示剩下的蛋糕矩形,amount表示下刀的距离,edge表示下刀的方位,它有四个取值:CGRectMinXEdge,CGRectMinYEdge,CGRectMaxXEdge,CGRectMaxYEdge。分别表示奶油的left,top,right,bottom边缘。被切下的两块蛋糕矩形outSlice和outRemainder会通过矩形指针返回。
CGRectstartingRect=CGRectMake(37.0,42.0,300.0,100.0);
CGRectslice,remainder;
CGRectDivide(startingRect,&slice,&remainder,100.0,CGRectMinXEdge);
桔色区域表示slice区域,棕色区域表示remainder区域。
slice值为{{37,42}{100,100}}
remainder值为{{137,42},{200,100}}
slice不会大于原始矩形。如果将amount的100改成-100。slice将得到一个{{37,42},{0,100}}的矩形,注意到矩形的宽变成了0。
CGRectDivide用法示例:
假设你现在需要在窗口内手动管理对象的布局。首先划分顶部矩形作为头区域。使用剩下的矩形作为内容区域。接着划分内容区域的底部矩形作为页脚信息区域。最后划分剩下的内容区域的两侧作为信息面板。剩下的区域即为内容区域。操作快照如下图:
CGRectstartingRect=CGRectMake(50.00,50.0,100.0,100.0);
CGRectremainder;
CGRectheaderRect;
CGRectDivide(startingRect,&headerRect,&remainder,20.0,CGRectMinYEdge);
CGRectfooterRect;
CGRectDivide(remainder,&footerRect,&remainder,10.0,CGRectMaxYEdge);
CGRectleftPanelRect;
CGRectDivide(remainder,&leftPanelRect,&remainder,15.0,CGRectMinXEdge);
CGRectrightPanelRect;
CGRectDivide(remainder,&rightPanelRect,&remainder,30,CGRectMaxXEdge);
CGRectcontentArea=remainder;
CGRectselection={{0.0,0.0},{200.0,100.0}};
CGRectthing1={{10.0,20.0},{80.0,80.0}};
CGRectthing2={{180.0,20.0},{100.0,40.0}};
检查指定的区域是否被选中:
if(CGRectContainsRect(selection,thing1))NSLog(@"thing1selected");if(CGRectContainsRect(selection,thing2))NSLog(@"thing2selected");
将打印“thing1selected”
检查是否有交集:
if(CGRectIntersectsRect(selection,thing1))NSLog(@"thing1selected");
if(CGRectIntersectsRect(selection,thing2))NSLog(@"thing2selected");
将打印“thing1selected”和“thing2selected”
CGRectIntersectsRect不仅用于检查是否被选中。你可能使用该函数以检查某些图形对象是否需要绘制。如果你现在需要管理一堆需要绘制于视图的对象,调用CGRectIntersectsRect函数可以快速判断当前对象是否与视图的可视区域存在交集,以决定是否需要绘制该对象。
CGRectweirdRect={100.0,100.0,-30.0,-50.0};
CGRectstandardRect=CGRectStandardize(weirdRect);
//输出:standardizing{{100,100},{-30,-50}}->{{70,50},{30,50}}
NSLog(@"standardizing%@->%@",NSStringFromRect(weirdRect),NSStringFromRect(standardRect));
CGRectdifferential=CGRectMake(0.5,0.2,99.9,105.5);
CGRectintegral=CGRectIntegral(differential);//输出(0,0,101,106)
-(void)scrollViewDidEndZooming:(UIScrollView*)scrollViewwithView:(UIView*)viewatScale:(CGFloat)scale{
scrollView.decelerationRate=scale<=scrollView.minimumZoomScale+FLT_EPSILONUIScrollViewDecelerationRateNormal:UIScrollViewDecelerationRateFast;
UIImage*originalImage=[UIImageimageNamed:@"Image.png"];
//scalingsetto2.0makestheimage1/2thesize.
UIImage*scaledImage=[UIImageimageWithCGImage:[originalImageCGImage]
scale:(originalImage.scale*2.0)
orientation:(originalImage.imageOrientation)];
NSString*documentsDirectory=[pathsobjectAtIndex:0];//Getdocumentsfolder
NSString*dataPath=[documentsDirectorystringByAppendingPathComponent:@"/MyFolder"];
if(![[NSFileManagerdefaultManager]fileExistsAtPath:dataPath]){
[[NSFileManagerdefaultManager]createDirectoryAtPath:dataPathwithIntermediateDirectories:NOattributes:nilerror:&error];//Createfolder
NSData*data=UIImagePNGRepresentation(image);
@interfaceUIImage(CacheExtensions)
+(id)cachedImageWithContentsOfFile:(NSString*)path;
+(void)clearCache;
staticNSMutableDictionary*UIImageCache;
@implementationUIImage(CacheExtensions)
+(id)cachedImageWithContentsOfFile:(NSString*)path
idresult;
if(!UIImageCache)
UIImageCache=[[NSMutableDictionaryalloc]init];
else{
result=[UIImageCacheobjectForKey:path];
if(result)
returnresult;
result=[UIImageimageWithContentsOfFile:path];
[UIImageCachesetObject:resultforKey:path];
+(void)clearCache
[UIImageCacheremoveAllObjects];
NSDate*start=[NSDatedate];
//dosomething
NSDate*methodFinish=[NSDatedate];
NSTimeIntervalexecutionTime=[methodFinishtimeIntervalSinceDate:start];
NSLog(@"ExecutionTime:%f",executionTime);
NSString*filePath=[[pathsobjectAtIndex:0]stringByAppendingPathComponent:@"Image.png"];
[UIImagePNGRepresentation(_gridImageType)writeToFile:filePathatomically:YES];
NSString*path=[[NSBundlemainBundle]pathForResource:@"icon_new"ofType:@"png"];
UIImage*originalImage=(UIImage*)[infovalueForKey:UIImagePickerControllerOriginalImage];
NSData*imgData=UIImageJPEGRepresentation(originalImage,1.0);
NSLog(@"SizeofImage(bytes):%d",[imgDatalength]);
NSError*errorReading;
NSString*filePath=[[NSBundlemainBundle]pathForResource:@"recordDetail3"ofType:@"xml"];
NSString*xmlString=[NSStringstringWithContentsOfFile:filePathencoding:NSUTF8StringEncodingerror:&errorReading];
NSDateFormatter*formatter=[[NSDateFormatteralloc]init];
[formattersetDateFormat:@"yyyy-MM-ddHH:mm:ss"];
NSDate*now=[NSDatedate];
NSString*dateFromString=[formatterstringFromDate:now];
NSMutableString*mutableString=[@"time"mutableCopy];
[mutableStringreplaceCharactersInRange:NSMakeRange(0,inspectorTime.length)withString:dateFromString];
UIPinchGestureRecognizer*pinchRecognizer=[[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(handlePinch:)];
[self.tableViewaddGestureRecognizer:pinchRecognizer];
-(void)handlePinch:(UIPinchGestureRecognizer*)pinchRecognizer{
if(pinchRecognizer.state==UIGestureRecognizerStateBegan){
CGPointpinchLocation=[pinchRecognizerlocationInView:self.tableView];
NSIndexPath*newPinchedIndexPath=[self.tableViewindexPathForRowAtPoint:pinchLocation];
self.pinchedIndexPath=newPinchedIndexPath;
NSString*sourceString=[[NSThreadcallStackSymbols]objectAtIndex:1];
NSCharacterSet*separatorSet=[NSCharacterSetcharacterSetWithCharactersInString:@"-[]+.,"];
NSMutableArray*array=[NSMutableArrayarrayWithArray:[sourceStringcomponentsSeparatedByCharactersInSet:separatorSet]];
[arrayremoveObject:@""];
NSLog(@"Stack=%@",[arrayobjectAtIndex:0]);
NSLog(@"Framework=%@",[arrayobjectAtIndex:1]);
NSLog(@"Memoryaddress=%@",[arrayobjectAtIndex:2]);
NSLog(@"Classcaller=%@",[arrayobjectAtIndex:3]);
NSLog(@"Functioncaller=%@",[arrayobjectAtIndex:4]);
NSLog(@"Linecaller=%@",[arrayobjectAtIndex:5]);}
staticNSMutableArray*allObjects=nil;
+(void)initialize{
if(!allObjects){
allObjects=[NSMutableArraynew];
-(id)init{
if(self=[superinit]){
//Eachobjectgetsheldinanarray
[allObjectsaddObject:self];
returnself;
+(void)doSomethingToEveryObject{
[allObjectsmakeObjectsPerformSelector:@selector(doSomethingToThisObject)];
-(void)doSomethingToThisObject{
NSLog(@"Didsomethingto%@",self);
-(void)dealloc{
[allObjectsremoveObject:self];
NSIndexPath*indexPath=[NSIndexPathindexPathForRow:rowinSection:section];
[tableViewselectRowAtIndexPath:indexPathanimated:YESscrollPosition:UITableViewScrollPositionNone];
ceil(x)返回不小于x的最小整数值(然后转换为double型)。
floor(x)返回不大于x的最大整数值。
round(x)返回x的四舍五入整数值。
UITextField*textField=[[UITextFieldalloc]initWithFrame:CGRectMake(10,200,300,40)];
textField.borderStyle=UITextBorderStyleRoundedRect;
textField.font=[UIFontsystemFontOfSize:15];
textField.placeholder=@"entertext";
textField.autocorrectionType=UITextAutocorrectionTypeNo;
textField.keyboardType=UIKeyboardTypeDefault;
textField.returnKeyType=UIReturnKeyDone;
textField.clearButtonMode=UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
textField.delegate=self;
[self.viewaddSubview:textField];
UIBezierPath*shadowPath=[UIBezierPathbezierPathWithRect:view.bounds];
view.layer.masksToBounds=NO;
view.layer.shadowColor=[UIColorblackColor].CGColor;
view.layer.shadowOffset=CGSizeMake(0.0f,5.0f);
view.layer.shadowOpacity=0.5f;
view.layer.shadowPath=shadowPath.CGPath;
myTextField.layer.sublayerTransform=CATransform3DMakeTranslation(5,0,0);
CAGradientLayer*moreLayer=[CAGradientLayerlayer];
CGColorRefouterColor=[UIColorcolorWithWhite:1.0alpha:0.0].CGColor;
CGColorRefmiddleColor1=[UIColorcolorWithWhite:1.0alpha:0.1].CGColor;
CGColorRefmiddleColor2=[UIColorcolorWithWhite:1.0alpha:0.9].CGColor;
CGColorRefinnerColor=[UIColorcolorWithWhite:1.0alpha:1.0].CGColor;
moreLayer.colors=@[(__bridgeid)innerColor,(__bridgeid)middleColor1,(__bridgeid)outerColor,(__bridgeid)outerColor,(__bridgeid)middleColor2,(__bridgeid)innerColor];
moreLayer.locations=@[@0.01,@0.034,@0.035,@0.90,@.95,@1.0];
moreLayer.bounds=CGRectMake(0,0,CGRectGetWidth(_detailView.frame),CGRectGetHeight(_detailView.frame));
moreLayer.anchorPoint=CGPointZero;
moreLayer.position=CGPointMake(CGRectGetWidth(_inspctorTableView.frame),0);