Domanda

I am developing an iOS application with Rubymotion which worked pretty fine until i added a new UIViewController. I have added the controller via xcode and have got just a UITextField as an element in it. On running the simulator and on displaying this particular scene, I get an instance of NSError. I also dont see the UITextField element in my screen.

Can any one please explain as to what it is and how do i handle the NSError and make sense out of it?

Any help at this point would be of great help.

UPDATE: I am getting the NSError instance every time my app is launched first, no matter what the controller is. I had upgraded to Xcode 5.1 yesterday. Wonder if that has something to do with the error.

UPDATE 2: This was result of a confusion on my part. I had assumed the NSError to have been raised after upgrading to Xcode 5.1 and thought it was some bug. The reason being was that I had had started using push notifications at the same time as I had upgraded to 5.1. As push notifications don't work in simulators, the NSError was being returned by the simulator. Messed it up big time and spent quite a few hours trying to debug this problem.

È stato utile?

Soluzione

NSError is a class and it is used as the preferred way to handle errors in objective-c. Usually it works like this: You declare a NSError pointer and sends the address to that one in as a parameter to a method that might fail. If something goes wrong in the method a NSError object is created and populated with info about the error and when the methods returns you can check the error object to se if anything went wrong.

NSError *error;
[someObject someFunctionWithParam:paramOne andError:&error];
if ( error ) {
    // Here you can inspect the error and act accordingly
    NSLog(@"%@", [error localizedDescription]);
}

If you are the one implementing a method it usually looks something like this.

- (void)someFunctionWithParameter:(NSString *)argOne andError:(NSError **)error {
    // something goes wrong
    *error = [NSError errorWithDomain:@"SomeDomain" code:500 userInfo:@{@"infoKey": @"some info"}];
}

So about the title of your question. There is no catching NSError's since they are not thrown. Only exceptions are thrown.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top