unexepted # in program - xcode

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.

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

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]];

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

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.

question about readwrite properties

One thing that I like about readwrite properties is that you get KVO compliance 'for free', so I tend to use it on properties even when they are only written to from within the object to which the property belongs. On the other hand, I understand that a property should only be set to readwrite if it is intended to be writeable by other objects. So, should I use readwrite even though I only call the setter from self:
[self setFoo:bar];
The alternative (I think) is to use:
[self willChangeValueForKey:#"foo"];
foo = bar;
[self didChangeValueForKey:#"foo"];
which is an extra two lines I code I have to write every time I want to change foo. Which is better?
You can declare a property readonly in the public interface, then promote it to readwrite in a class extension in the implementation file.
Foo.h:
#interface Foo: NSObject
#property (readonly) NSString *frob;
#end
Foo.m:
#interface Foo ()
#property (readwrite) NSString *frob;
#end
#implementation Foo
#synthesize frob;
// Methods in Foo.m can now use foo.frob = #"whatever";
#end
in .h
#property(nonatomic,readwrite,retain)NSString *foo;
then
in .m
#synthesize foo;
then use anywhere like
self.foo=#"madhu";
or
self.foo=#"mike";
but if u synthesized like above then u have to use always like
self with dot
everytime while change the string
it will automatically release the older object then retain the new one.so no pain to take care of old one for release and no pain for retain the new one.
i think its better

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