error: expected member name or ';' after declaration specifiers [1] - IBAction - xcode

Ever since I've upgraded to Xcode 4. I've got this error and i can't seem to figure out whats wrong.
error: expected member name or ';' after declaration specifiers [1]
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface SixViewController : UIViewController <AVAudioPlayerDelegate> {
IBOutlet UIImageView *play;
AVAudioPlayer *theAudio;
float progress;
NSTimer *timer;
IBOutlet UIProgressView *progressView;
int mainInt;
IBAction *timeOut;
}
It highlights the error on ibaction line
thanks

IBAction is intended as a return value for methods:
- (IBAction)someMethod;
... to tell Interface Builder that it is available for target/action connections. It is not intended as a variable data type, although you can get away with it when IBAction is defined as void.
However, you should use the correct data type for this variable, e.g. id for generic objects or maybe NSTimeInterval depending on what you're actually trying to do here.

Related

XCode 6.3 Warning: synthesize property

In new Xcode 6.3 I get this warning:
Auto property synthesis will not synthesize property 'homeInt'; it will be implemented by its superclass, use #dynamic to acknowledge intention
How I can remove it?
If you are overriding the same property from the super class on purpose, then in your *.m or *.mm file, add #dynamic like:
#implementation MyClass
#dynamic homeInt;
// ...
#end
If not, rename the property.
I simply removed this property declaration, because it has already been declared in parent class
Following on #mplace's comment, in my case I was overriding the property to refine the type of the property to a subclass of the original class of the property. So, I did need the #property override.
Here's what I'm using:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-property-synthesis"
// superclass type for currentValue was "id"
#property (nonatomic, strong) NSDate *currentValue;
#pragma clang diagnostic pop
Note that it's "-Wobjc-property-synthesis" and not "-Wno-objc-property-synthesis"
See also https://github.com/couchbase/couchbase-lite-ios/issues/660
If you want to avoid adding #dynamic <varName> each place that you have overridden a super class's property intentionally, you can add the -Wno-objc-property-synthesis flag to "Other Warning Flags" under your projects build settings. This will suppress the warning project-wide.
this cause by child class define the same property name override to parent class,such as:
1)child class "AFHTTPSessionManager" have define :
#property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * **responseSerializer**;
2)parent class "AFURLSessionManager" have define:
#property (nonatomic, strong) id <AFURLResponseSerialization> **responseSerializer**;
3)cause by above, warning come! if want remove it ,just rename the conflict property name!
4) or as it suggest, add "#dynamic homeInt" in your implement file;
If you updated to Xcode 6.3, simply update AFNetworking to version 2.5.2 and these warnings should disappear.
#synthesize homeInt = _ homeInt;
...
#end

unexepted # in program

I've created a UIViewController class with a XIB Attached. Without adding anything, the compiler tells me "UNEXEPTED # IN PROGRAM" on the .h file at the #interface line and repeat the same error on the #end line
#import <UIKit/UIKit.h>
#interface iPegasoDatiCorpoCli : UIViewController
-(id)initWithStrings:(NSString *)lblcorpo1 :(NSString *)lblcorpo2 :(NSString *)lblcorpo3 :(NSString *)<nibNameOrNil :(NSBundle *)nibBundleOrNil;
#end
This class is implemented to create a custo cell view and it worked till now. I've created also a new class just like this one but never used it and still gaves me the same error 3 Builds every 5. It's giving me headache
There is typo, extra > symbol in please check:
-(id)initWithStrings:(NSString *)lblcorpo1 :(NSString *)lblcorpo2 :(NSString *)lblcorpo3 :(NSString *)<nibNameOrNil :(NSBundle *)nibBundleOrNil;
----- ^
EDIT:
Why you are passing 6-7 arguments to a method. Wrap them in a class or pass an array of strings.

Xcode basics: Declare custom class with integer properties and use it in another class

Trying to do something really simple, but can't figure out the syntax.
I have a class called Word.h which has 8 properties, strings and integers. For the sake of keeping things simple, I'll stick to 2 here:
#import <UIKit/UIKit.h>
#interface Word : NSObject
#property (nonatomic, strong) NSString *word;
#property (nonatomic, strong) NSNumber *wordLevel;
#end
Both properties are synthesised in the .m file
I then want to create some objects in another file (UIViewController). In the .h file I have this:
#import "Word.h"
and in the .m file, this:
Word *newWord = [[Word alloc] init];
[newWord setWord:#"theorise"];
[newWord setWordLevel:6];
Word *newWord1 = [[Word alloc] init];
[newWord setWord:#"implicit"];
[newWord setWordLevel:7];
Word *newWord2 = [[Word alloc] init];
[newWord setWord:#"incredible"];
[newWord setWordLevel:9];
I now get an error message "Implicit conversion of 'int' to 'NSNumber *' is disallowed with ARC"
What am I doing wrong...is the property defined incorrectly in the class file?? How do I access this property. It works fine with the string.
I will also want to access the properties later - how do I do that...for example:
cell.label1.text = [newWord2 wordLevel];
Is this the right syntax???
Hoping someone can help me, tearing clumps of hair out here!
M
You declared wordLevel to be an NSNumber, an object. You are treating it in your code like it is a plain C int. You have to decide which your want it to be and treat it that way consistently. For example, for a plain C int property you would instead declare:
#property (nonatomic, assign) int wordLevel;
On the other hand if you really want wordLevel to be an NSNumber you need to use the setter like this:
[newWord setWordLevel:[NSNumber numberWithInt:6]];

Core Data Save Error (NSValidationErrorKey, Cocoa error 1570) saving NSDate

I'm getting an error with saving to a Core data object in Xcode.
Xcode says that the error is in the NSDate variable 'datum' but I have tried almost everything.
Error is:
2011-07-12 18:01:29.068 WeekLijstje[3205:207] Core Data Save Error
NSValidationErrorKey datum
NSValidationErrorPredicate (null)
NSValidationErrorObject
<DagLijst: 0x6e2fcd0> (entity: DagLijst; id: 0x6e2fd30 <x-coredata:///DagLijst/t99F423FC-AAE9-4692-9264-EF0FF7A020572> ; data: {
Voedsel = nil;
datum = nil;
hoeveelheid = 0;
punten = 0;
})
NSLocalizedDescription:The operation couldn’t be completed. (Cocoa error 1570.)
A small code snipet:
DagLijst *newDaglijst = [NSEntityDescription insertNewObjectForEntityForName:#"DagLijst" inManagedObjectContext:self.managedObjectContext];
NSDate *selDatum = [NSDate date];
newDaglijst.punten = [NSNumber numberWithInteger:10];
newDaglijst.hoeveelheid = [NSNumber numberWithInt:100];
newDaglijst.Voedsel = geselecteerdVoedsel;
newDaglijst.datum = selDatum;
NSError *error = nil;
if (![newDaglijst.managedObjectContext save:&error]) {
...
Also the class of the DagLijst object:
#interface DagLijst : NSManagedObject {
#private
}
#property (nonatomic, retain) NSDate * datum;
#property (nonatomic, retain) NSNumber * punten;
#property (nonatomic, retain) NSNumber * hoeveelheid;
#property (nonatomic, retain) Voedsel *Voedsel;
#end
So you can see that I put an NSDate into the 'datum' variable. But on execution I still get an error.
The cocoa error 1570 means that mandatory fields are not filled in.
In this case, your have two attribues that are nil : Voedsel and datum.
I see in your code :
newDaglijst.Voedsel = geselecteerdVoedsel;
newDaglijst.datum = selDatum;
Check that geselecteerdVoedsel and selDatum are not nil or that they are overreleased and finish to be nil.
If they are optional data (but I don't think so), define them as optional in coredata.
Hope this help,
as Michael A said. Check your attributes value are not nil.
There are 2 alternatives to get rid of these error.
Case 1:If 2 attributes are Required
If the 2 attributes are required attributes then it is mandatory to check the values you are passing are not nil,It may happens sometimes,If u want to get out of these error u have to give default values for those attributes in attributes inspector of your Entity in data Model
Case 2:
Set those attributes to optional in attribute inspector by selecting the check mark of optional.
Me too struggled for days to know these error.
Hope it helps someone.
Your logging would look like this:
Fatal error: 'try!' expression unexpectedly raised an error:
Error Domain=NSCocoaErrorDomain Code=1560 "(null)" UserInfo={NSDetailedErrors=(
...
It means you have an uncommitted change for one (or more) property of a entity, in which you told it is NOT optional, but you left it optional.
To find out which entity you failed to set value for a property, look for this in your logging:
UserInfo={NSValidationErrorObject=<YOURENTITYISHERE: ...>
To find out the property, search for:
NSValidationErrorKey=YOURPROPERTYISHERE
Somewhere in your code you forget to set a value for that property for the given entity.
I had this issue when I copied entities from other xcdatamodeld file.
They lost inverse attributes, so that was the reason.
Not really related with date, but with the error, I share it as this question has more views:
In my case, I was setting a BOOL property directly as YES or NO, but you should use
NSNumber numberWithBOOL
in order to make it work.
To reinforce Michael's answer, you can check your Entity properties in the inspector. One of your items may be accidentally considered Optional, or not. Or, if you're like me, your "Delete Rule" might have been set to "Nullify", which made my Entity's relationship property Nil at runtime. Because my object-to-be-deleted had a One-To-Many relationship with some other objects, it prevented the parent objects from being deleted. Changing it to Cascade solved the problem.
Entity Inspector - Delete Rule

Thread "does not implement" error with CLASS method in error string?

I've got the common-seeming error for beginning thread programmers, ".. does not implement selector.." except that it lists a CLASS method, not an instance method. Which makes perfect sense it's defined as an instance method.. Code:
main app delegate header:
#interface LSSampleAppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *window;
LSDataObject labelOptions;
}
-(void) doPrintDisc: (LSDataObject*) labelOptions;
#property (assign) IBOutlet NSWindow *window;
//-(void) userDidClickStop:(id)sender;
#end
thread function first line (in delegate object):
-(void) doPrintDisc: (LSDataObject*) labelOptions {
thread launch code:
[NSThread detachNewThreadSelector: #selector(doPrintDisc:)
toTarget: [self class]
withObject: labelOptions];
The error:
*** -[NSThread initWithTarget:selector:object:]: target does not implement selector (*** +[LSSampleAppDelegate doPrintDisc:])
I know, the printDisc method should probably go in the labelOptions object and not the delegate - but I want to get this working before I make another modification.. I've had enough problem today with a malloc error of some kind that seems to show up, only to go away with no apparent reason (it says it's out of memory, but I seriously doubt that it really is unless the lightscribe library itself has a limit on its memory zone) - I assume that the library may run out of memory and then perhaps reset and then the error goes away for a while.
The really odd thing is - earlier today I think I had the thread code actually working..
Try:
[NSThread detachNewThreadSelector: #selector(doPrintDisc:)
toTarget: self
withObject: labelOptions];
instead.

Resources