ios - NSFileManager instances changing other instance's currentDirectoryPath -
ios - NSFileManager instances changing other instance's currentDirectoryPath -
i subclassing nsfilemanager in ios app add together additional behaviours. while doing that, ran issue can demonstrate without subclassing.
in summary, create 1 instance of nsfilemanager, alter currentdirectorypath, print it, create instance, set currentdirectorypath else , end same currentdirectorypath on both instances.
this how replicate behaviour:
nsstring * patha = [nshomedirectory() stringbyappendingpathcomponent:@"directorya"]; nsstring * pathb = [nshomedirectory() stringbyappendingpathcomponent:@"directoryb"]; [[nsfilemanager defaultmanager] createdirectoryatpath:patha withintermediatedirectories:no attributes:nil error:nil]; [[nsfilemanager defaultmanager] createdirectoryatpath:pathb withintermediatedirectories:no attributes:nil error:nil]; nsfilemanager * filemanagera = [[ccfilemanager alloc] init]; [filemanagera changecurrentdirectorypath:patha]; nslog( @"filemanagera.currentdirectorypath = %@", filemanagera.currentdirectorypath ); // outputs patha, expected nsfilemanager * filemanagerb = [[ccfilemanager alloc] init]; [filemanagerb changecurrentdirectorypath:pathb]; nslog( @"filemanagerb.currentdirectorypath = %@", filemanagerb.currentdirectorypath ); // outputs pathb, expected nslog( @"filemanagera.currentdirectorypath = %@", filemanagera.currentdirectorypath ); // outputs pathb, why? i've tried both sdk 7.1 , 8.1 on ios 7 , 8 same results.
i found reply in documentation nsfilemanager.
all relative pathnames refer implicitly current working directory. changing current working directory affects paths created in current process.
the currentdirectorypath changed entire process , not instance of nsfilemanager
ios objective-c nsfilemanager
Comments
Post a Comment