Reputation: 751
THE ANSWER ACCEPTED GAVE ME THE CORRECT EXPLANATION OF THE PROBLEM. I ALSO EDITED THE QUESTION PUTTING THE ANSWER POINT BY POINT IN CAPITAL LETTERS TO MAKE IT CLEARER
I have a c++ code in MacOSX, that use a bit of CoreFoundation.
I use the following function CFPropertyListCreateWithData
in my code that takes a CFErrorRef *error
as one of its parameters. Well, I create CFErrorRef myError
and pass it as &myError
First problem: I think there is a bug in the Documentation, because it gives me some good data as result, but the error is NOT NULL. If I have an error, the data should be NULL, shouldn't it? Or did I misunderstand the documentation?
FIRST SOLUTION: THE ERROR IS UNDEFINED IF THERE IS NO ERROR, SO I HAD TO CHECK THE ERROR ONLY IF THE DATA WERE NULL. MOREOVER I WAS RELEASING USING CFRelease
A UNDEFINED OBJECT, THE ERROR, THAT CAUSED MY PROGRAM TO CRASH WITH A SEGMENTATION FAULT
Second problem: I want to check which is the error.
Well I get into this function CFErrorCopyFailureReason
, doc here,
but it takes a CFError and not a CFErrorRef, and gives me a CFString. Then, how can I transform my CFErrorRef to CFError?
SECOND SOLUTION: NOSENSE QUESTION, I WAS READING THE DOCUMENTATION OF SWIFT AND NOT OF OBJECTIVE-C
Third problem: the function CFErrorCopyFailureReason
gives me a CFString
, but I do not know where the CFString
is defined! it is not in CoreFoundation/CoreFoundation.h
and neither in CoreFoundation/CFString.h
, and I have a undefined type error when I try to compile.
Then: In which file is CFString
defined? Can I convert it to CFStringRef
, and how can I do it?
THIRD SOLUTION: NOSENSE QUESTION, I WAS READING DOCUMENTATION OF SWIFT AND NOT OF OBJECTIVE-C
Fourth problem: with the code I have, if I use CFStringRef
and CFErrorRef
instead of CFString
and CFError
, it compiles, but then I have a NSInvalidArgumentException
. Shouldn't I have an error at compilation time? I would not like a RunTimeException...
FOURTH SOLUTION: AS THE ANSWER MADE ME UNDERSTAND, I HAD TO CHECK THE ERROR ONLY IF THE DATA WAS NULL. IN THAT CASE I WAS CHECKING A ERROR WITH UNDEFINED DATA THAT GAVE ME THE INVALID ARGUMENT EXCEPTION. OBVIOUSLY, SINCE THE PROBLEM WAS UNDEFINED VALUE IN THE ERROR, THIS IS A RUNTIME EXCEPTION
Well, to conclude, I just want to read and write a Info.plist
file in my c++ application. I take inspiration from this, Saving and Restoring Property Lists, sample code and modified it quite a bit. If you have a working sample how to read and modify a Info.plist
file, please tell me :) but without using PlistBuddy or other tools please, only c++ API.
TO CONCLUDE: THE SAMPLE CODE WORKS WELL, I JUST MISUNDERSTOOD THE DOCUMENTATION
Thanks to everybody
Upvotes: 0
Views: 517
Reputation: 3236
I think you are misunderstanding the documentation for CFPropertyListCreateWithData()
: if it succeeds, the return value is non-NULL, and what error
points to is not defined. Don't worry about error
unless CFPropertyListCreateWithData()
returns NULL.
CFErrorCopyFailureReason()
does take a CFErrorRef
and return a CFStringRef
. You might be looking at the Swift documentation for it, change the language to Objective-C on the top of the documentation page.
Which call is throwing the exception, CFPropertyListCreateWithData()
?
Upvotes: 2