diff --git a/include/wx/osx/core/cfstring.h b/include/wx/osx/core/cfstring.h index e74423ecea..5eaa325f76 100644 --- a/include/wx/osx/core/cfstring.h +++ b/include/wx/osx/core/cfstring.h @@ -76,4 +76,28 @@ public: private: } ; +/*! @function wxCFStringRefFromGet + @abstract Factory function to create wxCFStringRefRef from a CFStringRef obtained from a Get-rule function + @param p The CFStringRef to retain and create a wxCFStringRefRef from. May be NULL. + @discussion Unlike the wxCFStringRef raw pointer constructor, this function explicitly retains its + argument. This can be used for functions ) which return a temporary reference (Get-rule functions). +*/ +inline wxCFStringRef wxCFStringRefFromGet(CFStringRef p) +{ + return wxCFStringRef(wxCFRetain(p)); +} + +#ifdef __WXMAC__ +/*! @function wxCFStringRefFromGet + @abstract Factory function to create wxCFStringRefRef from a NSString* obtained from a Get-rule function + @param p The NSString pointer to retain and create a wxCFStringRefRef from. May be NULL. + @discussion Unlike the wxCFStringRef raw pointer constructor, this function explicitly retains its + argument. This can be used for functions ) which return a temporary reference (Get-rule functions). +*/ +inline wxCFStringRef wxCFStringRefFromGet(NSString *p) +{ + return wxCFStringRefFromGet((CFStringRef)p); +} +#endif + #endif //__WXCFSTRINGHOLDER_H__ diff --git a/src/osx/cocoa/dirdlg.mm b/src/osx/cocoa/dirdlg.mm index 156f067aa4..b47a2c9039 100644 --- a/src/osx/cocoa/dirdlg.mm +++ b/src/osx/cocoa/dirdlg.mm @@ -194,8 +194,8 @@ size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayI name = [filemanager displayNameAtPath:path]; - paths.Add(wxCFStringRef(path).AsString()); - names.Add(wxCFStringRef(name).AsString()); + paths.Add(wxCFStringRefFromGet(path).AsString()); + names.Add(wxCFStringRefFromGet(name).AsString()); } }