Re: Using CFMutableDictionaryRef
Re: Using CFMutableDictionaryRef
- Subject: Re: Using CFMutableDictionaryRef
- From: Alexander Hartner <email@hidden>
- Date: Mon, 1 Mar 2010 01:12:27 +0000
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@hidden)
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:
This email sent to email@hidden