Data-core NSException - objective-c

I don't know where is my problem because the entity "Utente" exist.
Error code:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente''
*** First throw call stack:
(
0 CoreFoundation 0x0000000101bf0495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001016f099e objc_exception_throw + 43
2 CoreData 0x0000000101e76599 +[NSEntityDescription entityForName:inManagedObjectContext:] + 217
3 CoreData 0x0000000101eb2e7e +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 30
4 VucmpraJson 0x000000010000514b -[LoginViewController login:] + 4843
5 UIKit 0x000000010029ef06 -[UIApplication sendAction:to:from:forEvent:] + 80
6 UIKit 0x000000010029eeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
7 UIKit 0x000000010037b880 -[UIControl _sendActionsForEvents:withEvent:] + 203
8 UIKit 0x000000010037adc0 -[UIControl touchesEnded:withEvent:] + 530
9 UIKit 0x00000001002d5d05 -[UIWindow _sendTouchesForEvent:] + 701
10 UIKit 0x00000001002d66e4 -[UIWindow sendEvent:] + 925
11 UIKit 0x00000001002ae29a -[UIApplication sendEvent:] + 211
12 UIKit 0x000000010029baed _UIApplicationHandleEventQueue + 9579
13 CoreFoundation 0x0000000101b7fd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x0000000101b7f5f2 __CFRunLoopDoSources0 + 242
15 CoreFoundation 0x0000000101b9b46f __CFRunLoopRun + 767
16 CoreFoundation 0x0000000101b9ad83 CFRunLoopRunSpecific + 467
17 GraphicsServices 0x00000001040d0f04 GSEventRunModal + 161
18 UIKit 0x000000010029de33 UIApplicationMain + 1010
19 VucmpraJson 0x0000000100021d13 main + 115
20 libdyld.dylib 0x00000001025f15fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Code:
#property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;
.
.
.
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject * Utente = [NSEntityDescription insertNewObjectForEntityForName:#"Utente" inManagedObjectContext:context];
[Utente setValue: emailText.text forKey:#"email"];
NSError *error;
//[context save:&error];
if (![context save:&error]) {
NSLog(#"Whoops, couldn't save: %#", [error localizedDescription]);
}
entities: Utente
attributes: email;password
thx to much guys

nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente'
means that your managed object context is nil. Check self.managedObjectContext assignment.
edit
if (! [self managedObjectContext]) {
NSLog(#"You will receive your exception");
} else {
// Insert new entity into specified context
}

Related

Call to UIWebView crashing my app in iOS

I have a WebView in my storyboard. I created an outlet property to that webview in my view controller file. Then in my code in I'm calling it like this:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"news1" ofType:#"html" inDirectory:#"/HTML"]];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}
The problem is my app is crashing when I run this and I don't really know why. I get this error, but I need help deciphering what the issue is.
2014-05-20 20:18:10.214 MyApp[1789:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(
0 CoreFoundation 0x01f7b1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x019fe8e5 objc_exception_throw + 44
2 CoreFoundation 0x01f7afbb +[NSException raise:format:] + 139
3 Foundation 0x0161a92b -[NSURL(NSURL) initFileURLWithPath:] + 123
4 Foundation 0x0161a7fd +[NSURL(NSURL) fileURLWithPath:] + 67
5 MyApp 0x00011c3d -[LVGTutorialVC viewDidLoad] + 205
6 UIKit 0x007dd33d -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x00803345 -[UINavigationController _layoutViewController:] + 39
8 UIKit 0x0080385b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
9 UIKit 0x00803953 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
10 UIKit 0x008048cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
11 UIKit 0x008054e9 -[UINavigationController __viewWillLayoutSubviews] + 57
12 UIKit 0x009460d1 -[UILayoutContainerView layoutSubviews] + 213
13 UIKit 0x0072d964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x01a1082b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x01de245a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x01dd6244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x01dd60b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18 QuartzCore 0x01d3c7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x01d3db85 _ZN2CA11Transaction6commitEv + 393
20 QuartzCore 0x01d3e258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21 CoreFoundation 0x01f4336e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22 CoreFoundation 0x01f432bf __CFRunLoopDoObservers + 399
23 CoreFoundation 0x01f21254 __CFRunLoopRun + 1076
24 CoreFoundation 0x01f209d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x01f207eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x03eab5ee GSEventRunModal + 192
27 GraphicsServices 0x03eab42b GSEventRun + 104
28 UIKit 0x006bef9b UIApplicationMain + 1225
29 MyApp 0x0002158d main + 141
30 libdyld.dylib 0x0262c701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The HTML file isn't in your bundle or isn't at the path specified. Check the case of the file and folder name. If you build/run in the simulator, you can look through the bundle inside of ~/Library/Application Support/iPhone Simulator/7.1/Applications.
Don't use loadRequest if you want to load html locally. use this
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];

UIAlertView crashes in iOS7

We had compiled and deployed an app in iOS 6 environment. But, now the app is getting crash in iOS 7 whenever showing an alert.
App simply getting crash in [alertView show];
But, the same app is running perfect in iOS 6.
Code for showing alert
-(void)displayAlertWithMessage:(NSString *)message withTitle:(NSString *)title andTag:(int)tag
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
and calling like this
[self displayAlertWithMessage:#"Please enter valid username!" withTitle:nil andTag:1];
Here, is the crash log.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/developer/Library/Application Support/iPhone Simulator/7.0/Applications/A0BCB945-8E4A-4D06-BEE8-240FF45ECF78/MyProject.app> (loaded)' with name '_UIModalItemAppViewController''
*** First throw call stack:
(
0 CoreFoundation 0x003176f4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x027c88b6 objc_exception_throw + 44
2 CoreFoundation 0x003174cb +[NSException raise:format:] + 139
3 UIKit 0x015d1bec -[UINib instantiateWithOwner:options:] + 951
4 UIKit 0x01444f05 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
5 UIKit 0x014456ad -[UIViewController loadView] + 302
6 UIKit 0x014459ae -[UIViewController loadViewIfRequired] + 78
7 UIKit 0x01445eb4 -[UIViewController view] + 35
8 UIKit 0x018dc9da -[_UIModalItemsCoordinator _presentingViewControllerForAlertCompatibilityCreateIfNeeded:] + 248
9 UIKit 0x018dc8dd -[_UIModalItemsCoordinator _presentingViewControllerForAlertCompatibility] + 41
10 UIKit 0x01812801 -[UIAlertView(Private) popupAlertAnimated:animationType:atOffset:] + 382
11 UIKit 0x01812c1d -[UIAlertView(Private) popupAlertAnimated:animationType:] + 56
12 UIKit 0x01817c17 -[UIAlertView showWithAnimationType:] + 48
13 UIKit 0x01817c45 -[UIAlertView show] + 41
14 MyProject 0x000330a8 -[LoginViewController displayAlertWithMessage:withTitle:andTag:] + 232
15 MyProject 0x00032e8b -[LoginViewController isValidContent] + 299
16 MyProject 0x00033136 -[LoginViewController showSetPinView] + 54
17 libobjc.A.dylib 0x027da874 -[NSObject performSelector:withObject:withObject:] + 77
18 UIKit 0x0133524c -[UIApplication sendAction:to:from:forEvent:] + 108
19 UIKit 0x013351d8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
20 UIKit 0x0142ba5d -[UIControl sendAction:to:forEvent:] + 66
21 UIKit 0x0142be20 -[UIControl _sendActionsForEvents:withEvent:] + 577
22 UIKit 0x0142b0cf -[UIControl touchesEnded:withEvent:] + 641
23 UIKit 0x0137221d -[UIWindow _sendTouchesForEvent:] + 852
24 UIKit 0x01372e84 -[UIWindow sendEvent:] + 1232
25 UIKit 0x01346b86 -[UIApplication sendEvent:] + 242
26 MyProject 0x000c2c75 -[Application sendEvent:] + 101
27 UIKit 0x0133135f _UIApplicationHandleEventQueue + 11421
28 CoreFoundation 0x002a096f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x002a02fb __CFRunLoopDoSources0 + 235
30 CoreFoundation 0x002bd3ce __CFRunLoopRun + 910
31 CoreFoundation 0x002bcbf3 CFRunLoopRunSpecific + 467
32 CoreFoundation 0x002bca0b CFRunLoopRunInMode + 123
33 GraphicsServices 0x036f0a27 GSEventRunModal + 192
34 GraphicsServices 0x036f084e GSEventRun + 104
35 UIKit 0x01333f0b UIApplicationMain + 1225
36 MyProject 0x00006612 main + 178
37 MyProject 0x00006555 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Thanks in advance.
As per crash log it says to me "[UIViewController _loadViewFromNibNamed:bundle:]" unable to load nib file.
But, in my project I had created a category for UIViewController class and overridden the -(id)init method. Upto ios6, while showing an alert this category method is not at all executing, but from ios7 onwards overridden init() method of UIViewController.
So, I fixed this issue by adding the another validation in UIViewController category's init() method for checking the class method is UIAlertView or not, if it is UIAlertView then simply calling [super init]; instead of doing my other stuff relating to view controllers.
Sample code:
- (id)init
{
NSString *viewControllerName = [NSString stringWithFormat:#"%#",[self class]];
if([viewControllerName isEqualToString:#"UIAlertView"])
{
self = [super init];
}
else
{
// my stuff
}
return self;
}
you can test it.. try to avoid nil.. instead of that put something... like
[self displayAlertWithMessage:#"Please enter valid username!" withTitle:#"Hello" andTag:1]
and you need to release alert view so in function write release code...

NSMutableArray adding/removing objects + NSUserDefaults

I want to make a "Favorites" in my RSS reader. My RSS parser is parsing a RSS feed to NSMutableArray, and then object "item" is created from part of my rss (selected post).
My code:
//Creating mutable array and adding items:
- (void)viewDidLoad {
if (favoritedAlready == nil) {
favoritedAlready = [[NSMutableArray alloc] init];
[[NSUserDefaults standardUserDefaults] setObject:favoritedAlready forKey:#"favorites"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(#"избранное с нуля");
}
}
- (void) addToFavorites {
NSMutableArray* favoritedAlready = [[NSUserDefaults standardUserDefaults] objectForKey:#"favorites"];
[favoritedAlready addObject: item];
[[NSUserDefaults standardUserDefaults] setObject:favoritedAlready forKey:#"favorites"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(#"Добавлено в избранное. В избранном %i статей", [favoritedAlready count]);
}
//Removing items (another View)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
rssItems = [[NSUserDefaults standardUserDefaults] objectForKey:#"favorites"];
[self.tableView reloadData];
NSLog(#"Загрузилось избранное, %i избранных статей", [rssItems count]);
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"Номерок строчки в которой удаляемый объект %i", indexPath.row+1);
[rssItems removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[[NSUserDefaults standardUserDefaults] setObject:rssItems forKey:#"favorites"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
It worked perfectly initially, but when I added and removed items, it started crashing.
Crash logs:
I added object to Favorites and removed it:
2011-09-25 20:14:44.534 ARSSReader[36211:11303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object'
*** Call stack at first throw:
(
0 CoreFoundation 0x015505a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x016a4313 objc_exception_throw + 44
2 CoreFoundation 0x01508ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x01508e6a +[NSException raise:format:] + 58
4 CoreFoundation 0x01547dd1 -[__NSCFArray removeObjectAtIndex:] + 193
5 ARSSReader 0x000a0ced -[FavoritesView tableView:commitEditingStyle:forRowAtIndexPath:] + 173
6 UIKit 0x00876037 -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
7 UIKit 0x0080b4fd -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x0089b799 -[UIControl sendAction:to:forEvent:] + 67
9 UIKit 0x0089dc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
10 UIKit 0x0089c7d8 -[UIControl touchesEnded:withEvent:] + 458
11 UIKit 0x0082fded -[UIWindow _sendTouchesForEvent:] + 567
12 UIKit 0x00810c37 -[UIApplication sendEvent:] + 447
13 UIKit 0x00815f2e _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x01c91992 PurpleEventCallback + 1550
15 CoreFoundation 0x01531944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x01491cf7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x0148ef83 __CFRunLoopRun + 979
18 CoreFoundation 0x0148e840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x0148e761 CFRunLoopRunInMode + 97
20 GraphicsServices 0x01c901c4 GSEventRunModal + 217
21 GraphicsServices 0x01c90289 GSEventRun + 115
22 UIKit 0x00819c93 UIApplicationMain + 1160
23 ARSSReader 0x00001e79 main + 121
24 ARSSReader 0x00001df5 start + 53
)
terminate called throwing an exception(gdb)
But, if I added item, restarted app and then removed it, it worked perfectly.
I added item, restarted app, removed item, and tried to add new item:
2011-09-25 20:19:19.212 ARSSReader[36461:11303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'
*** Call stack at first throw:
(
0 CoreFoundation 0x015505a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x016a4313 objc_exception_throw + 44
2 CoreFoundation 0x01508ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x01508e6a +[NSException raise:format:] + 58
4 CoreFoundation 0x01547cf1 -[__NSCFArray insertObject:atIndex:] + 209
5 CoreFoundation 0x01544c14 -[__NSCFArray addObject:] + 68
6 ARSSReader 0x00004b35 -[DetailsViewController addToFavorites] + 149
7 UIKit 0x0080b4fd -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x00a1dcc3 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
9 UIKit 0x0080b4fd -[UIApplication sendAction:to:from:forEvent:] + 119
10 UIKit 0x0089b799 -[UIControl sendAction:to:forEvent:] + 67
11 UIKit 0x0089dc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
12 UIKit 0x0089c7d8 -[UIControl touchesEnded:withEvent:] + 458
13 UIKit 0x0082fded -[UIWindow _sendTouchesForEvent:] + 567
14 UIKit 0x00810c37 -[UIApplication sendEvent:] + 447
15 UIKit 0x00815f2e _UIApplicationHandleEvent + 7576
16 GraphicsServices 0x01c91992 PurpleEventCallback + 1550
17 CoreFoundation 0x01531944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
18 CoreFoundation 0x01491cf7 __CFRunLoopDoSource1 + 215
19 CoreFoundation 0x0148ef83 __CFRunLoopRun + 979
20 CoreFoundation 0x0148e840 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x0148e761 CFRunLoopRunInMode + 97
22 GraphicsServices 0x01c901c4 GSEventRunModal + 217
23 GraphicsServices 0x01c90289 GSEventRun + 115
24 UIKit 0x00819c93 UIApplicationMain + 1160
25 ARSSReader 0x00001e79 main + 121
26 ARSSReader 0x00001df5 start + 53
)
terminate called throwing an exception(gdb)
In addToFavorites
NSMutableArray* favoritedAlready = [[NSUserDefaults standardUserDefaults] objectForKey:#"favorites"];
will return an NSArray (it makes no difference it you save a mutable version), not an NSMutableArray
You need to create a mutable version:
NSMutableArray* favoritedAlready = [[[NSUserDefaults standardUserDefaults] objectForKey:#"favorites"] mutableCopy];
You can obviously not add items to a non-mutable array. Also just casting the return value to a NSMutableArray is wrong, it may work or it may not but that is irrelevant.
The issue is that NSUserDefaults only returns immutable arrays, even if you put in a mutable array:
Special Considerations:
The returned array and its contents are immutable, even if the values you originally set were mutable.
Therefore, when you fetch your array from NSUserDefaults, you'll have to convert it by using the mutable copy method, or by creating a new NSMutableArray using the returned NSArray.
You may want to consolidate changes to fewer method calls to NSUserDefaults—perhaps in batches, perhaps at certain time intervals. Have a local array keep track of changes, then write the changes out, rather than grabbing the array from NSUserDefaults first. This will save one more trip to disk and will make your code more efficient as well.

Why am I getting invalidArgument exception while running unit test?

Inside my Table view controller I have following method
-(BOOL)isValidCoordinate:(CLLocationCoordinate2D)coordinate
{
//This is just to make sure exception is always thrown a cut down version of method
[NSException raise:#"Invalid longitude value" format:#"Longitude of %d is invalid", coordinate.longitude];
return TRUE;
}
I am running a unit test against it and I it failing giving following exception
2011-10-04 22:58:43.380 navman2[74159:ec03] -[MapViewController isValidCoordinate:]: unrecognized selector sent to instance 0x5e20830
2011-10-04 22:58:43.382 navman2[74159:ec03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapViewController isValidCoordinate:]: unrecognized selector sent to instance 0x5e20830'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f555a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010a9313 objc_exception_throw + 44
2 CoreFoundation 0x00f570bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00ec6966 ___forwarding___ + 966
4 CoreFoundation 0x00ec6522 _CF_forwarding_prep_0 + 50
5 navman2Tests 0x05765b41 -[navman2Tests testExceptionThrownBycoordinatesCheck] + 193
6 CoreFoundation 0x00ec5c7d __invoking___ + 29
7 CoreFoundation 0x00ec5b51 -[NSInvocation invoke] + 145
8 SenTestingKit 0x201043d2 -[SenTestCase invokeTest] + 69
9 SenTestingKit 0x20104aa7 -[SenTestCase performTest:] + 192
10 SenTestingKit 0x201041d3 -[SenTest run] + 88
11 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
12 SenTestingKit 0x201041d3 -[SenTest run] + 88
13 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
14 SenTestingKit 0x201041d3 -[SenTest run] + 88
15 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
16 SenTestingKit 0x201041d3 -[SenTest run] + 88
17 SenTestingKit 0x201067a4 +[SenTestProbe runTests:] + 174
18 Foundation 0x0092e79e __NSFireDelayedPerform + 441
19 CoreFoundation 0x00f368c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
20 CoreFoundation 0x00f37e74 __CFRunLoopDoTimer + 1220
21 CoreFoundation 0x00e942c9 __CFRunLoopRun + 1817
22 CoreFoundation 0x00e93840 CFRunLoopRunSpecific + 208
23 CoreFoundation 0x00e93761 CFRunLoopRunInMode + 97
24 GraphicsServices 0x016171c4 GSEventRunModal + 217
25 GraphicsServices 0x01617289 GSEventRun + 115
26 UIKit 0x001b5c93 UIApplicationMain + 1160
27 navman2 0x000028b9 main + 121
28 navman2 0x00002835 start + 53
)
terminate called throwing an exception(gdb)
Unit test is following:
#import "navman2Tests.h"
#import "TableViewController.h"
#import "MapViewController.h"
#implementation navman2Tests
- (void)setUp
{
[super setUp];
// Set-up czode here.
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
- (void) testExceptionThrownBycoordinatesCheck
{
TableViewController *newView2 =[[MapViewController alloc] init];
CLLocationCoordinate2D coordinate;
double lat = 61.2180556;
double lng = -149.9002778;
coordinate.latitude = lat;
coordinate.longitude = lng;
STAssertThrows([newView2 isValidCoordinate:coordinate],#"some text description");
[newView2 release];
}
#end
The error is that you did declare newView2 as a TableViewController not a MapViewController (which has that method), change:
TableViewController *newView2 =[[MapViewController alloc] init];
with:
MapViewController *newView2 =[[MapViewController alloc] init];
anyway I would call the variable newViewController rather than newView2 :P

NSURLRequest throwing runtime error

Trying to create a request only to have a runtime error thrown. Method initiating the request:
- (void)loadMemberData {
//build URL
NSMutableString *url = [[NSMutableString alloc] initWithString:appDelegate.apiURL];
[url appendFormat:#"&subaction=singlestat&memberID=%d", [[NSUserDefaults standardUserDefaults] integerForKey:#"memberID"]];
NSURL *tempURL = [[NSURL alloc] initWithString:url];
NSLog(#"URL: %#", tempURL);
//Create conn
NSURLRequest *request = [[NSURLRequest alloc] requestWithURL:tempURL];
NSLog(#"%#", request);
//conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
//[request release];
}
The URL logs correctly. I have even checked the object type to make sure everything is correct, and all seems good. No compile time errors or warnings. Stack Trace & Log:
[Session started at 2011-03-09 15:02:32 -0500.]
2011-03-09 15:02:33.807 NTR Beer Club[17702:207] URL: https://mydomain.com/path/to/file.php?action=get_app_data&subaction=singlestat&memberID=117
2011-03-09 15:02:33.809 NTR Beer Club[17702:207] -[NSURLRequest requestWithURL:]: unrecognized selector sent to instance 0x4b02cf0
2011-03-09 15:02:33.811 NTR Beer Club[17702:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLRequest requestWithURL:]: unrecognized selector sent to instance 0x4b02cf0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00db7be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f0c5c2 objc_exception_throw + 47
2 CoreFoundation 0x00db96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d29366 ___forwarding___ + 966
4 CoreFoundation 0x00d28f22 _CF_forwarding_prep_0 + 50
5 NTR Beer Club 0x00002190 -[MyStats loadMemberData] + 358
6 NTR Beer Club 0x000022c8 -[MyStats viewDidLoad] + 215
7 UIKit 0x004b64f0 -[UINib instantiateWithOwner:options:] + 1556
8 UIKit 0x004b8081 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x002c2943 -[UIApplication _loadMainNibFile] + 172
10 UIKit 0x002c34ca -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
11 UIKit 0x002cddb2 -[UIApplication handleEvent:withNewEvent:] + 1533
12 UIKit 0x002c6202 -[UIApplication sendEvent:] + 71
13 UIKit 0x002cb732 _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x016eda36 PurpleEventCallback + 1550
15 CoreFoundation 0x00d99064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00cf96f7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00cf6983 __CFRunLoopRun + 979
18 CoreFoundation 0x00cf6240 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00cf6161 CFRunLoopRunInMode + 97
20 UIKit 0x002c2fa8 -[UIApplication _run] + 636
21 UIKit 0x002cf42e UIApplicationMain + 1160
22 NTR Beer Club 0x00001b98 main + 102
23 NTR Beer Club 0x00001b29 start + 53
24 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
You should be doing
NSURLRequest *request = [NSURLRequest requestWithURL:tempURL];
The requestWithURL: creates NSURLRequest objects that are autorelease-d.
The actual error message says "unrecognized selector" because requestWithURL: is a class method, but you are using it like an instance method.