Reputation: 17
I'm working on my project in Xcode writing in Objective C & I like to know, is there a way to duplicate files? I keep looking it up on the internet & in my books, I can't fond anything. Whenever I try to #include, it doesn't seem to work.
This is what I have so far, this is the .h file.
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController {
}
- (IBAction)link;
@end
#include <UIKit/UIKit.h>
@interface ViewController2 :UIViewController {
}
- (IBAction)link;
@end
This is the /m file which doesn't want to work.
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)link {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"https://twitter.com/sexybeast914"]];
}
@end
#include "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)link {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"https://twitter.com/sexybeast914"]];
}
@end
I always get the same to errors, "Cannot declare class extension for "ViewController", & "Reimplementation of class "ViewController"
If someone could help, it would be nice.
Thanks, :)
Upvotes: 0
Views: 615
Reputation: 162722
You are declaring the class ViewController
twice. You can't have two classes of the same name.
I'm betting that second copy of ViewController
was meant to be ViewController2
and you forgot to rename it in the file after copy/pasting the code from the first file?
Upvotes: 1