• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is this correct behavior?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is this correct behavior?


  • Subject: Re: Is this correct behavior?
  • From: Rune Lindman <email@hidden>
  • Date: Thu, 30 Jun 2005 15:02:00 +0200

Thanks Jim!

Great explanation to my problem. I was actually using the TCFDictionary class from PowerPlant and this defaults to nil for these parameters. I have now changed as you suggested. This explains problems I had long time ago where I didn't understand why I had to retain under certain conditions and not under other.

On 30 jun 2005, at 13.50, Jim Correia wrote:

On Jun 30, 2005, at 4:10 AM, Rune Lindman wrote:


Moving from GCC 4 to 3.3 is a much larger step for me than moving from CW to Xcode. I encountered several small issues with code that used to work but suddenly stopped. Most where easy to get around by rearranging the code.

Now I'm totally stuck on a problem. I have code that used to work fine but stopped to work either when I moved from GCC 4 to 3.3 or I changed some settings in Xcode. Have I been getting away with something illegal before or is there a problem/setting I missed?

This does not work (key is not found in dictionary):
-------------
#define kMyKey CFSTR("myKey")

CFMutableDictionaryRef dictRef = ::CFDictionaryCreateMutable(nil, 0,nil,nil);
CFDictionarySetValue(dictRef,kMyKey,CFSTR("myValue"));
CFStringRef returnedValue = CFDictionaryGetValue(dictRef,kMyKey);
CFShow(returnedValue); // null


This works:
-------------
#define kMyKey CFSTR("myKey")

CFStringRef key = kMyKey;
CFMutableDictionaryRef dictRef = ::CFDictionaryCreateMutable(nil, 0,nil,nil);
CFDictionarySetValue(dictRef,key,CFSTR("myValue"));
CFStringRef returnedValue = CFDictionaryGetValue(dictRef,key);
CFShow(returnedValue); // "myKey"


Grateful for any hints!


You are passing NULL for the key and value callbacks. You should be using the appropriate standard callback blocks from CFDictionary.h instead of NULL.


Using NULL has several implications when putting CFTypes into a dictionary. One is that the dictionary cannot retain/release your values for you, so you must make sure the values lives longer than the dictionary. Another side effect of this is that the dictionary has to use pointer equality tests instead of a logical equals on your keys, which is why you aren't getting the value back as you expected. (The implementation reason for this is that CFSTR can make real static strings, or is a macro that makes a singleton at runtime, depending on the compiler and settings in use.)

Jim


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Is this correct behavior? (From: Rune Lindman <email@hidden>)
 >Re: Is this correct behavior? (From: Jim Correia <email@hidden>)

  • Prev by Date: Re: Is this correct behavior?
  • Next by Date: Re: Xcode 2.1 can't (manually) save files
  • Previous by thread: Re: Is this correct behavior?
  • Next by thread: Using XCode with an alterlnative GDB such as AVR-GDB
  • Index(es):
    • Date
    • Thread