Xcode : 15.0.1 (15A507) Mac OS: 14.3.1
I am working on Mac OS application which should parse files in binary format. This is document based application, but before I'll prepare visual representation, I want to parse file and create some kind of internal representation.
I got stuck with debugging code:
@try {
NSFileHandle *fileHandle;
NSFileManager *fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:self.filePath]) {
// Yes! File exists - shown both in "Run" and "Test" mode
fileHandle = [NSFileHandle fileHandleForReadingAtPath:self.filePath];
// return nil in "Run" mode
if (fileHandle) {
[fileHandle seekToFileOffset:0]; // перемотка в начало для уверенности
self.header = [[EDFHeader alloc] initWithFile:fileHandle];
if (self.header) {
// Load data...
}
}
else {
// Cannot open file! Get hererin "Run" mode
[NSException raise:INVALID_FILE_ACCESS format:FILE_NOT_OPEN];
}
}
}
@catch (NSException *exception) {
@throw;
}
In Run mode (Cmd-R) I gor exception, as fileHandle returned is nil. As soon I am trying to run it through testing mode (Cmd-U) file is accessed and I can work without any problems.
I suspect that Run and Test modes have different assumptions about "sandboxing". But, unfortunately, I do not see any mention about sandbox in in latest Xcode.
I switch on access to User selected files in application' profile but no changes.
will be grateful for any ideas.
Thanks in advance.
Tried to run code in Test mode and in Run mode in the Xcode. Works OK in Test mode, and cannot open file in Run mode.
I tried to "downgrade" to use minimal Unix-like construction:
FILE *libFile = fopen("/Users/<MyUserDir>/AI/EDF Analysezer/TestFiles/6720119.edf","r");
if(libFile){
char wah[200];
fgets(wah, 200, libFile);
printf("%s test\n", wah);
}
Behavior is the same :-(
So I suggest issue is in some environment or application setting, not in the code itself.