Using CFMutableDictionaryRef
Using CFMutableDictionaryRef
- Subject: Using CFMutableDictionaryRef
- From: Alexander Hartner <email@hidden>
- Date: Sun, 28 Feb 2010 23:09:41 +0000
This my be a little off topic, but I am trying to store a list of UITouch events in a dictionary as suggested in the Apple Documentation.
This is what I have come up with, but it's not working. The documentation refers to a MultiTouchDemo which I can't find anywhere online. So with some help from the dev forums I put this together. It doesn't work. For some reason I am not able to retrieve the same object I put into the dictionary.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touchesBegan count : %i",[touches count]);
CFMutableDictionaryRef aTouchSession = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if ([touches count] > 0)
{
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 : %i Point : %i",&touch,&pointDict);
CGPoint beginPoint = *(CGPoint *)CFDictionaryGetValue(aTouchSession, touch);
NSLog(@"Fetched Touch : %i Point : %i",&touch,&beginPoint);
NSLog(@"Stored : %f / %f Fetched : %f / %f", point.x, point.y, beginPoint.x, beginPoint.y);
CFRelease(pointDict);
}
else
{
NSLog(@"Not Stored Touch : %i",&touch);
}
}
}
}
and this is the output it produces
Stored Touch : -1073749800 Point : -1073749808
Fetched Touch : -1073749800 Point : -1073749824
Stored : 160.000000 / 206.000000 Fetched : 0.000000 / 0.000000
showing that the object retrieved is not the same as I put in. Any suggestion on what I am doing wrong and how I can fix this._______________________________________________
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