Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-13-2010, 02:16 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 243
benoitr007 is on a distinguished road
Default "Assignment of read-only variable" in completion handler

Hello,

I am not familiar with completion handlers, but I'm adding Game Center functionality to my game and need the following code:

Code:
BOOL submit_ok = FALSE;
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
	if (error == nil) {
		submit_ok = TRUE;
	}
}];
However, I get the following error:

Quote:
Assignment of read-only variable "submit_ok"
How am I supposed to access that variable inside the completion handler? Thank you very much!

Benoit
benoitr007 is offline   Reply With Quote
Old 09-13-2010, 07:38 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 243
benoitr007 is on a distinguished road
Default

Any help on this would be very appreciated... I tried to find an answer online but really don't know where to look. Thanks in advance!
benoitr007 is offline   Reply With Quote
Old 09-13-2010, 09:07 PM   #3 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

I haven't personally used blocks since they became available, but after taking a cursory glance at the documentation on Apple's site (Blocks Programming Topics), I think the key bit you might be missing is the __block specifier for your BOOL variable:
Code:
__block BOOL submit_ok = FALSE;
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
	if (error == nil) {
		submit_ok = TRUE;
	}
}];
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 09-13-2010, 09:56 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 243
benoitr007 is on a distinguished road
Default

Thanks, I don't get any errors that way, but unfortunately, I am unable to access the variable outside the block now. I think what I am trying to do (and the way I'm trying to do it) is not really possible, I'll try another solution. Thank you very much!
benoitr007 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 329
14 members and 315 guests
Absentia, cgokey, fiftysixty, givensur, heshiming, iGamesDev, linkmx, michaelhansen, mraalex, PixelInteractive, raihan.zbr, Sloshmonster, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,117
Posts: 402,890
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:07 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0