The following code seem to work correction. I had to use 
CGPointMakeWithDictionaryRepresentation to re-construct a CGPoint. I am still a 
little confused why the pointer addresses are different when storing and 
accessing the objects from the dictionary though. 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
  NSLog(@"touchesBegan count : %i",[touches count]);      
  touchSession = CFDictionaryCreateMutable(NULL, 0, 
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
  
  if ([touches count] > 0) 
  {
    for (UITouch * touch in touches) 
    {
      CGPoint * existingPoint = (CGPoint *)CFDictionaryGetValue(touchSession, 
touch);
      if (existingPoint == NULL) 
      {
        CGPoint point = [touch locationInView:self.view];
        
        CFDictionaryRef pointDict = 
CGPointCreateDictionaryRepresentation(point);                
        CFDictionaryAddValue(touchSession, touch, pointDict);
        NSLog(@"Stored  Touch : %p Point : %p", &touch, &pointDict);
        CFRelease(pointDict);        
        
        CFDictionaryRef fetchedPointDict = 
(CFDictionaryRef)CFDictionaryGetValue(touchSession, touch);
        NSLog(@"Fetched Touch : %p Point : %p", &touch, &fetchedPointDict);    
        
        CGPoint fetchedPoint;
        CGPointMakeWithDictionaryRepresentation(fetchedPointDict, 
&fetchedPoint);
        NSLog(@"Stored : %f / %f Fetched : %f / %f", point.x, point.y, 
fetchedPoint.x, fetchedPoint.y);               
      }
      else 
      {
        NSLog(@"Not Stored Touch : %i",&touch);        
      }
    }
  }
}

On 1 Mar 2010, at 01:12, Alexander Hartner wrote:

> I have made some modifications. I am using local variables at this stage to 
> debug this problem. However once I got this working I will be using a member 
> variable for the touchSession.
> 
> When I debug this and set a brake point after fetching the point from the 
> dictionary, but the pointDict and the fetchedPoint appear in red which tells 
> me that they have not been properly defined and initialised, but I don't know 
> what else I can do to resolve this.
> 
> Updated Code:
> CFMutableDictionaryRef aTouchSession = CFDictionaryCreateMutable(NULL, 0, 
> &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
> 
> for (UITouch * touch in touches) 
> {
>       CGPoint * existingPoint = (CGPoint 
> *)CFDictionaryGetValue(aTouchSession, touch);
>       if (existingPoint == NULL) 
>       {
>               CGPoint point = [touch locationInView:self.view];
>               
>               CFDictionaryRef pointDict = 
> CGPointCreateDictionaryRepresentation(point);                
>               CFDictionaryAddValue(aTouchSession, touch, pointDict);
>               NSLog(@"Stored  Touch : %p Point : %p", &touch, &pointDict);
>               CFRelease(pointDict);        
>               
>               CFDictionaryRef fetchedPoint = 
> (CFDictionaryRef)CFDictionaryGetValue(aTouchSession, touch);
>               NSLog(@"Fetched Touch : %p Point : %p", &touch, &fetchedPoint); 
>    
>               
>               //NSLog(@"Stored : %f / %f Fetched : %f / %f", point.x, 
> point.y, beginPoint.x, beginPoint.y);
>       }
>       else 
>       {
>               NSLog(@"Not Stored Touch : %i",&touch);        
>       }
> }
> 
> Output:
> Stored  Touch : 0xbfffe0d8 Point : 0xbfffe0d0
> Fetched Touch : 0xbfffe0d8 Point : 0xbfffe0cc
> 
> Thanks for your help so far
> Alex
> 
> 
> 
> On 28 Feb 2010, at 23:56, Fritz Anderson wrote:
> 
>> On 28 Feb 2010, at 5:09 PM, Alexander Hartner wrote:
>> 
>>> CFDictionaryAddValue(aTouchSession, touch, pointDict);
>>> NSLog(@"Stored Touch : %i Point : %i",&touch,&pointDict);
>>>                     
>>> CGPoint beginPoint = *(CGPoint *)CFDictionaryGetValue(aTouchSession, touch);
>>> NSLog(@"Fetched Touch : %i Point : %i",&touch,&beginPoint);
>> 
>>      
>> ... where touch is (UITouch *), pointDict is CFDictionaryRef, aTouchSession 
>> is a mutable dictionary initialized to have ==>CFType<== keys and values, 
>> and beginPoint is CGPoint, all local variables.
>> 
>> 1. You do realize that your %i's, applied to pointers to your stack 
>> variables, are just printing out the signed decimal integer representation 
>> of the addresses of those variables (assuming int and pointer are the same 
>> size on the current architecture)?
>> 
>> 2. You do realize that the return value of CFDictionaryGetValue, with the 
>> dictionary set up as you did, will be of a CoreFoundation object, and that 
>> CGPoint is just a struct, not a Core Foundation object? In fact, you stored 
>> pointDict into it, which is a CFDictionary, not a CGPoint. Taking the 
>> CFDictionaryRef you got back from aTouchSession, and casting it to CGPoint * 
>> won't make it a pointer to a CGPoint. Try pulling the values out with 
>> CFDictionary functions.
>> 
>>      — F
>> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/alex%40j2anywhere.com
> 
> This email sent to [email protected]

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to