I have error:
[2194:c07] CoreData: error: Failed to call designated initializer on NSManagedObject class 'Event'
2012-12-08 12:00:57.505 eventCost[2194:c07] -[Event setType:]: unrecognized selector sent to instance 0x7456dd0
2012-12-08 12:00:57.523 eventCost[2194:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Event setType:]: unrecognized selector
I have protocol at my addEventController:#protocol
AddEventControllerDelegate
- (void) addEventControllerDidSave:(NSString *) typeText;
- (void) addEventControllerDidCancel:(Event *) personToDelete;
#end
the implementation of the protocol:
- (void) addEventControllerDidCancel:(Event *)EventToDelete{
[[self currentPerson] removeEventsObject:EventToDelete];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) addEventControllerDidSave:(NSString *)typeText{
Event *newEvent = [[Event alloc]init];
[newEvent setType:typeText];
[currentPerson addEventsObject:newEvent];
[self dismissViewControllerAnimated:YES completion:nil];
}
also I have this segue for add new event:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier]isEqualToString:#"addEvent"])
{
AddEventController *aec = (AddEventController *) [segue destinationViewController];
aec.delegate = self;
}
}
I just try to add new Event with type property but I have this error and I don't understand what wrong..
The problem is that you're trying to send an NSManagedObject an init message.
You need to use - (id)initWithEntity: (NSEntityDescription *) entity insertIntoManagedObjectContext: (NSManagedObjectContext *) context
see the documentation here: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/NSManagedObject.html
Related
I have two Cocoa Applications, one is going to be the sender and another the receiver in this XPC relationship.
In the applicationDidFinishLaunching in the sender, I first open the second receiver application
NSError* error = nil;
NSURL* url = [[NSBundle mainBundle] bundleURL];
url = [url URLByAppendingPathComponent:#"Contents" isDirectory:YES];
url = [url URLByAppendingPathComponent:#"MacOS" isDirectory:YES];
url = [url URLByAppendingPathComponent:#"TestXPCHelper.app" isDirectory:YES];
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:url
options:NSWorkspaceLaunchWithoutActivation
configuration:[NSDictionary dictionary]
error:&error];
if ( error )
{
NSLog(#"launchApplicationAtURL:%# error = %#", url, error);
[[NSAlert alertWithError:error] runModal];
}
Then I create my NSXPCConnection
assert([NSThread isMainThread]);
if (self.testConnection == nil) {
self.testConnection = [[NSXPCConnection alloc] initWithMachServiceName:NEVER_TRANSLATE(#"com.TechSmith.TestXPCHelper") options:NSXPCConnectionPrivileged];
self.testConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:#protocol(TestXPCProtocol)];
self.testConnection.interruptionHandler = ^{
NSLog(#"Connection Terminated");
};
self.testConnection.invalidationHandler = ^{
self.testConnection.invalidationHandler = nil;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
self.testConnection = nil;
}];
};
[self.testConnection resume];
}
Then I try to send a message over the connection (the connection is already invalidated by here)
id<TestXPCProtocol> testRemoteObject= [self.testConnection remoteObjectProxy];
[testRemoteObject testXPCMethod2];
[[self.testConnection remoteObjectProxyWithErrorHandler:^(NSError * proxyError){
NSLog(#"%#", proxyError);
}] testXPCMethod:^(NSString* reply) {
NSLog(#"%#", reply);
}];
And here is the app delegate for my receiver application:
#interface AppDelegate () <NSXPCListenerDelegate, TestXPCProtocol>
#property (weak) IBOutlet NSWindow *window;
#property NSXPCListener *xpcListener;
#end
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSLog(#"TESTING123");
self.xpcListener = [[NSXPCListener alloc] initWithMachServiceName:#"com.TechSmith.TestXPCHelper"];
self.xpcListener.delegate = self;
[self.xpcListener resume];
}
- (void)applicationDidBecomeActive:(NSNotification *)notification {
NSLog(#"ACTIVE234");
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (void)run
{
NSLog(#"RUNNING");
// Tell the XPC listener to start processing requests.
[self.xpcListener resume];
// Run the run loop forever.
[[NSRunLoop currentRunLoop] run];
}
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
{
NSLog(#"LISTENING");
assert(listener == self.xpcListener);
#pragma unused(listener)
assert(newConnection != nil);
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:#protocol(TestXPCProtocol)];
newConnection.exportedObject = self;
[newConnection resume];
return YES;
}
- (void)testXPCMethod:(void(^)(NSString * version))reply
{
NSLog(#"HEY");
reply(#"REPLY HERE");
}
- (void)testXPCMethod2
{
NSLog(#"TWO!");
}
Here is the proxyError when I try to send a message over the connection:
Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service
named com.TechSmith.TestXPCHelper was invalidated." UserInfo={NSDebugDescription=The
connection to service named com.TechSmith.TestXPCHelper was invalidated.}
So I think I am doing something wrong with my instantiation of the NSXPCConnection. I can't find a good example of two applications speaking to eachother-- it's always one application and a service. Is that what my problem is? I need a service inbetween the applications talking?
Is there any way to get more information on why this connection is being invalidated? That would also help a lot
So pretty straight forward problem here,
Turns out initWithMachServiceName is explicitly looking for a mach service. I was using an identifier of another application process.
If I actually use an identifier of a valid mach service, there is no issue
Note that there are two other ways to create an NSXPCConnection,
with an NSXPCEndpoint or with a XPCService identifier
- (void)viewDidLoad
{
[super viewDidLoad];
//array with image filenames and country names
_paths = [[NSBundle mainBundle] pathsForResourcesOfType:#"png" inDirectory:self.itemName];
NSLog(#"%#",self.itemName);
_country=_paths;
for(int i=0;i <[_paths count];i++)
{
NSString *append=[_paths objectAtIndex:i];
NSString *temp= [NSArray arrayWithObject:[[ append componentsSeparatedByString:#"/"] lastObject]];
NSString *temp1= [NSArray arrayWithObject:[[ append componentsSeparatedByString:#"-"] lastObject]];
[_paths replaceObjectAtIndex:i withObject:temp];
[_country replaceObjectAtIndex:i withObject:temp1];
}
// Connect data
self.myPickerView.dataSource = self;
self.myPickerView.delegate = self;
self.maxIndex = [_country count];
self.displayedFlagIndex = arc4random() % self.maxIndex;
[self.ImageItem setImage:[UIImage imageNamed: _paths[self.displayedFlagIndex]]];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc]
initWithTarget:self action:#selector(tapHandler:)];
tapGR.numberOfTapsRequired = 1; // set appropriate GR attributes
self.ImageItem.userInteractionEnabled = YES;
[self.ImageItem addGestureRecognizer:tapGR]; // add GR to view
self.myTextield.delegate=(id)self;
}
// set image displayed based on item selected
// self.itemImage.image = [images objectAtIndex:self.itemNumber];
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) tapHandler: (UITapGestureRecognizer *) sender
{
_myTextield.text=#"";
NSLog(#"in tapHandler");
self.displayedFlagIndex = arc4random() % self.maxIndex;
[self.ImageItem setImage:[UIImage imageNamed: _paths[self.displayedFlagIndex]]];
}
I am trying to implement navigation controller with a table view and view controllers. Will post more code if required.
I have checked that the tapRecognizer method calls the tapHandler: method and not any other. But it still throws the exception of unrecognized selector sent to the instance.
-Thanks!
Your issue is that _paths[self.displayedFlagIndex] returns a NSArray (with one object) object whereas you expect a NSString for imageNamed: method of UIImage.
That's why you're getting the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]:
unrecognized selector sent to instance 0x7fd563f3a140'
The origin of your issue:
NSString *temp = [NSArray arrayWithObject:[[append componentsSeparatedByString:#"/"] lastObject]];
NSString *temp1 = [NSArray arrayWithObject:[[append componentsSeparatedByString:#"-"] lastObject]];
This should clearly throw a warning saying that's you can mix like that NSString and NSArray
You should do this instead:
NSString *temp = [[append componentsSeparatedByString:#"/"] lastObject];
NSString *temp1 = [[append componentsSeparatedByString:#"-"] lastObject];
i have a problem with and IBAction in my code. Everytime i click the button this Exception appears:
2013-01-15 22:25:00.798 FitnessApp[3478:c07] -[__NSCFString cancel:]: unrecognized selector sent to instance 0x93a7e50
2013-01-15 22:25:00.800 FitnessApp[3478:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString cancel:]: unrecognized selector sent to instance 0x93a7e50'
i already searched for this error. however the solutions here on stackoverflow didnt work.
My connections are all correctly set. no dublicate connections or something like that.
My Code:
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:NSLocalizedString(#"Placeholder_Description", nil)];
[self.navigationController setToolbarHidden:NO];
[self.navigationController.toolbar setTintColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]];
[self.buttonCancel setTarget:NSLocalizedString(#"Cancel_Button", nil)];
[self.buttonSave setTarget:NSLocalizedString(#"Save_Button", nil)];
[self.textViewDescription.layer setBorderColor:[[UIColor grayColor] CGColor]];
[self.textViewDescription.layer setBorderWidth:1.0];
[self.textViewDescription.layer setCornerRadius:8.0f];
[self.textViewDescription.layer setMasksToBounds:YES];
[self.textViewDescription setText:[self textViewDescriptionText]];
}
- (IBAction)cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)save:(id)sender {
[self.delegate doSaveDescription:self withDescription:[self.textViewDescription text]];
[self dismissViewControllerAnimated:YES completion:nil];
}
i made some NSLogs to find out that the IBAction is the problem because there never was an output after clicking the buttons, just the exception.
So what can i do if the connections are correctly set?
I have some problems with ViewDeck with my app. I'm trying to use it with storyboard and the examples only shows how to use it with nibfiles. I have checked out many ways to do it here on stackexchange but i don't seem to get it to work.
My code in appdelegate.m file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//UIViewController* leftController = [[UIViewController alloc] init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
RightViewController* rightController = [[RightViewController alloc] initWithNibName:#"RightViewController" bundle:nil];
ViewController* centerController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.centerController = [[UINavigationController alloc] initWithRootViewController:centerController];
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:self.centerController rightViewController:rightController];
deckController.rightSize = 100;
self.window.rootViewController = deckController;
[self.window makeKeyAndVisible];
return YES;
}
I of course i get the expected error:
2012-12-29 03:55:18.501 Network[27451:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Rostgaard/Library/Application Support/iPhone Simulator/6.0/Applications/C2BADD3B-660E-4363-8FC7-932B4E9D6172/Network.app> (loaded)' with name 'RightViewController''
*** First throw call stack:
(0x17cd012 0x15f2e7e 0x17ccdeb 0x755fac 0x61ae37 0x61b418 0x61b648 0x61b882 0xbcdf 0xe673 0xb7e2 0xada7 0x61d753 0x61da7b 0x61e964 0x581877 0x5885a3 0x580eed 0x56ab56 0x56adbf 0x56af55 0x573f67 0x2546 0x5377b7 0x537da7 0x538fab 0x54a315 0x54b24b 0x53ccf8 0x261adf9 0x261aad0 0x1742bf5 0x1742962 0x1773bb6 0x1772f44 0x1772e1b 0x5387da 0x53a65c 0x226d 0x2195 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Here is the code I'm using which works fine:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
UIViewController* menuController = [mainStoryboard instantiateViewControllerWithIdentifier:#"LeftSideMenu"];
UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController;
self.viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil];
self.window.rootViewController = self.viewDeckController;
}
Well, solved this myself by using ECSlidingViewController instead, already optimized with storyboard.
https://github.com/edgecase/ECSlidingViewController
Just in case anyone runs into the same problem.
Try this tutorial project, it works
i'm new to Cocoa and I'm having a little trouble with a sample app i'm writing :
#implementation DeviceDetection
- (id) init {
self = [super init];
if (self) {
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:#selector(discMounted:)
name:#"NSWorkspaceDidMountNotification"
object:[NSWorkspace sharedWorkspace]]; // Register for all notifications
}
return self;
}
- (void)discMounted:(NSNotification *)notification
{
NSLog(#"COUCOU");
}
#end
#import <Foundation/Foundation.h>
#interface DeviceDetection : NSObject {
NSNotificationCenter *notCenter;
}
- (void) discMounted:(NSNotification *)notification;
#end
#implementation AppDelegate
#synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
DeviceDetection* d = [[DeviceDetection alloc] init];
[d value];
}
#end
With that piece of code i'm getting a the following error when I plug-in a USB drive :
[NSRunLoop discMounted:]: unrecognized selector sent to instance 0x10054c5a0
Any reason why ?
Thx
You need to define dealloc method of DeviceDetection-
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
EDIT 1 -
DrivesOnDock[5207:707] -[DeviceDetection value]: unrecognized selector sent to instance 0x100475b40 when the app starts.
Above error occurs because you haven't defined value in DeviceDetection class.