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 11-29-2011, 02:15 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default missing block__type specifier error.

I have made a custom class named Box and also an array
called boxes full of Box objects.

Code:
Box *newBox;

if (something)
{
    newBox = [boxes objectAtIndex:0];
}
Code:
Box *newBox;

if (something)
{
    newBox = (Box *)[boxes objectAtIndex:0];
}
The code above throws the error: "missing block__type specifier".
__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis is offline   Reply With Quote
Old 11-29-2011, 02:28 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

where is the code that you declare "boxes" and add your objects to it?
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 11-29-2011, 02:55 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by nick.keroulis View Post
I have made a custom class named Box and also an array
called boxes full of Box objects.

Code:
Box *newBox;

if (something)
{
    newBox = [boxes objectAtIndex:0];
}
Code:
Box *newBox;

if (something)
{
    newBox = (Box *)[boxes objectAtIndex:0];
}
The code above throws the error: "missing block__type specifier".

Make sure you #import "Box.h" at the top of this .m file, so the compiler knows what a Box object is.

Also, you posted 2 variants of the same code. the second version casts the item from the boxes array to the right type before assigning it to the newBox variable. That's right. The first version lacks the type cast, so the compiler is going to throw a warning.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 11-29-2011, 03:15 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Quote:
Originally Posted by RickSDK View Post
where is the code that you declare "boxes" and add your objects to it?
Code:
NSMutableArray *boxes;
I have imported the "Box.h" file.

Also if you have a function like:

Code:
-(void)userSmashedBox:(Box *)box
{
   Box *newBox;

   newBox = box;
}
It throws the same error.
__________________
iDamaged Hands-On Preview. I like this game check it out.

Last edited by nick.keroulis; 11-29-2011 at 03:17 PM.
nick.keroulis is offline   Reply With Quote
Old 11-29-2011, 03:26 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

there's probably something wrong with your box.m file or .h file
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 11-30-2011, 02:26 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Quote:
Originally Posted by RickSDK View Post
there's probably something wrong with your box.m file or .h file
What could possibly the error be? The .h, .m files include nothing else than
the standard initialization function. Should i add something else?

.h
Code:
#import "Foundation/Foundation.h"

@interface Box : NSObject
{
    UIImage *img;
}
@property (nonatomic, retain) UIImage *img;

-(id)initWithImage:(UIImage *)newImg;

@end
.m
Code:
@implementation Box
@synthesize img;

-(id)initWithImage:(UIImage *)newImg
{
   if (self = [super init])
    {
        self.img = newImg;
    }
    
    return self;
}

@end
__________________
iDamaged Hands-On Preview. I like this game check it out.

Last edited by nick.keroulis; 12-01-2011 at 07:04 AM.
nick.keroulis is offline   Reply With Quote
Old 11-30-2011, 06:36 PM   #7 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

The missing semi-colon (; ) on the end of the "return self" line would cause this error.
__________________
My development blog: http://jrinn.com

Last edited by JasonR; 11-30-2011 at 06:36 PM. Reason: Remove smilie
JasonR is offline   Reply With Quote
Old 12-01-2011, 07:12 AM   #8 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Quote:
Originally Posted by JasonR View Post
The missing semi-colon (; ) on the end of the "return self" line would cause this error.
I misspelled it. Sorry. Actually there is a semicolon.

I can initialize a Box no prob.

Code:
Box *box = [[Box alloc] initWithImage:[UIImage imageNamed:@"blue.png"]];
Even this code works:

Code:
#import "Foundation/Foundation.h"
#import "Box.h"

@interface ViewController : UIViewController
{
    Box *currentBox;
}
@property (nonatomic, retain) Box *currentBox;

-(void)doSomething;
@end
Code:
#import "ViewController.h"

@implementation ViewController
@synthesize currentBox;

-(void)doSomething
{
    Box *anotherBox = [[Box alloc] initWithImage:[UIImage imageNamed:@"blue.png"]];
   currentBox = anotherBox;
}
@end
__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis is offline   Reply With Quote
Old 12-01-2011, 07:16 AM   #9 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Quote:
Originally Posted by nick.keroulis View Post
I misspelled it. Sorry. Actually there is a semicolon.

I can initialize a Box no prob.

Code:
Box *box = [[Box alloc] initWithImage:[UIImage imageNamed:@"blue.png"]];
Even this code works:

Code:
#import "Foundation/Foundation.h"
#import "Box.h"

@interface ViewController : UIViewController
{
    Box *currentBox;
}
@property (nonatomic, retain) Box *currentBox;

-(void)doSomething;
@end
Code:
#import "ViewController.h"

@implementation ViewController
@synthesize currentBox;

-(void)doSomething
{
    Box *anotherBox = [[Box alloc] initWithImage:[UIImage imageNamed:@"blue.png"]];
   currentBox = anotherBox;
}
@end
But this code DOES NOT work. !!!???

Code:
-(void)doSomethingElse:(Box *)box
{
   Box *aBox;
   aBox = box;
}
__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis is offline   Reply With Quote
Old 12-01-2011, 07:27 AM   #10 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Is that the exact error message? Are you sure it isn't "missing __block type specifier"?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 12-01-2011, 07:41 AM   #11 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Is that the exact error message? Are you sure it isn't "missing __block type specifier"?
Yeah!, The error is: "missing__block type specifier".
__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis is offline   Reply With Quote
Old 12-01-2011, 08:52 AM   #12 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Precision matters in programming. You've just wasted a lot of time because you did not accurately describe the situation.

Somewhere you are doing a block operation ^{} and messing with a variable that was declared outside the block. You have to prefix with __block in those situations.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 12-01-2011, 02:55 PM   #13 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Precision matters in programming. You've just wasted a lot of time because you did not accurately describe the situation.

Somewhere you are doing a block operation ^{} and messing with a variable that was declared outside the block. You have to prefix with __block in those situations.
Yes a UIView animate ...

The _block prefix should be added only within the ^{} block?
At every variable? or just the custom ones? When exactly?
When assigning what variables? Why does it exist? Im asking
so many questions when i should google it but i cant find any
documentation on _block prefix. I didn't even knew it existed.
__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis is offline   Reply With Quote
Old 12-01-2011, 02:56 PM   #14 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Loading…
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 12-01-2011, 07:59 PM   #15 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by BrianSlick View Post
Brian,

I have a block question for you, relating to blocks using/modifying local variables from the scope in which they are invoked.

If I have a local function that declares a variable foo:

Code:
__block int foo;
And I define a block inline, I can refer to, and change the value of, foo, within the code of the block. So, if I invoke a system method that takes a block as a parameter, I can have that block use local variables for input, and even write changed values to those local variables.

What if I have a block variable that's defined elsewhere. Can I pass that block variable to a system method, and have the code defined in that block variable read/write values that are defined in the scope where I actually invoke the block? If so, how do I tell the block code about the type of the variable that will exist in the block's lexical scope at the time the block is invoked?

So, in my example, say I'm writing an instance method aMethod that has a local variable foo, defined as __block.

Say I have a block variable called blockOfCode that is defined elsewhere. If in aMethod I pass the block variable blockOfCode to a system function, can blockOfCode access the variable foo which is defined in aMethod?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 12-02-2011, 07:59 AM   #16 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Not sure, I'm not real strong with blocks myself.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 12-02-2011, 08:57 AM   #17 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Brian,

I have a block question for you, relating to blocks using/modifying local variables from the scope in which they are invoked.

If I have a local function that declares a variable foo:

Code:
__block int foo;
And I define a block inline, I can refer to, and change the value of, foo, within the code of the block. So, if I invoke a system method that takes a block as a parameter, I can have that block use local variables for input, and even write changed values to those local variables.

What if I have a block variable that's defined elsewhere. Can I pass that block variable to a system method, and have the code defined in that block variable read/write values that are defined in the scope where I actually invoke the block? If so, how do I tell the block code about the type of the variable that will exist in the block's lexical scope at the time the block is invoked?

So, in my example, say I'm writing an instance method aMethod that has a local variable foo, defined as __block.

Say I have a block variable called blockOfCode that is defined elsewhere. If in aMethod I pass the block variable blockOfCode to a system function, can blockOfCode access the variable foo which is defined in aMethod?
Loading…

__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis 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: 406
16 members and 390 guests
AppsBlogger, chiataytuday, Clouds, David-T, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, leostc, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,912
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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