Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 4 Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning iOS 4 Application Development
This is the forum to discuss the Wrox book Beginning iOS 4 Application Development by Wei-Meng Lee; ISBN: 978-0-470-91802-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 17th, 2013, 07:58 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2013
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Unhappy chapter 20 - use of undeclared identifier

'm newbie c Objective programmer, i'm trying to built location based service application, but i have no idea what happen here, could anyone help?? i'm working on xcode 4.6 and iphone 6 SDK

Code:
#import "ViewController.h"

@interface ViewController ()


@end

@implementation ViewController

- (void)viewDidLoad

{
    self.lm = [[CLLocationManager alloc]init];
    lm.delegate = self;
    lm.desiredAccuracy = kCLLocationAccuracyBest;
    lm.distanceFilter = kCLDistanceFilterNone;
    [lm startUpdatingLocation];
    [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
}

    -(void) locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager
                               didUpdateToLocation : (CLLocation *) newLocation
                                      fromLocation : (CLLocation *) oldLocation {
    
    //display latitude
        NSString *lat = [[NSString alloc]initWithFormat : @"%f", newLocation.coordinate.latitude];
        latitudeTextField.text = lat;
        
    //display longitude
        NSString *lng = [[NSString alloc]initWithFormat : @"%f", newLocation.coordinate.longitude];
        longitudeTextField.text = lng;
        
    //display accuracy
        NSString *acc = [[NSString alloc]initWithFormat : @"%f", newLocation.horizontalAccuracy];
        accuracyTextField.text = acc;
        
        
        [acc release];
        [lat release];
        [lng release];
        
    }

-(void) locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager
                              didFailWithError : (NSError *) error {
    NSString *msg = [[NSString alloc]initWithTitle : @"Error"
                                           message : msg
                                          delegate : nil
                                 cancelButtonTitle : @"Done"
                                 otherButtonTitles : nil];
    
    [alert show]; //use of undeclared identifier 'alert'
    [message show];//use of undeclared identifier 'show'
    [alert release]; //use of undeclared identifier 'alert'

}

-(void)dealloc{
    [lm release];
    [latitudeTextField release];
    [longitudeTextField release];
    [accuracyTextField release];
    [super dealloc];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Reply With Quote
  #2 (permalink)  
Old October 17th, 2013, 10:13 PM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

I assume that in the header file you have a property for a CLLocationManager named "lm" and since there are no @synthesize statements in the implementation file you are using Xcode's auto-generation of accessors. When Xcode generates the accessors the variable is redefined with a leading underscore, so lm becomes _lm. What this means is that you can only access lm by using self.lm, which calls the accessor or set the variable directly, bypassing the accessor by using _lm.
So, in the viewDidLoad method (changes in bold)

Code:
- (void)viewDidLoad

{
    self.lm = [[CLLocationManager alloc]init];
    self.lm.delegate = self;
    self.lm.desiredAccuracy = kCLLocationAccuracyBest;
    self.lm.distanceFilter = kCLDistanceFilterNone;
    [self.lm startUpdatingLocation];
    [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
}
or bypassing the accessor and setting the variable directly

Code:
- (void)viewDidLoad

{
    _lm = [[CLLocationManager alloc]init];
    _lm.delegate = self;
    _lm.desiredAccuracy = kCLLocationAccuracyBest;
    _lm.distanceFilter = kCLDistanceFilterNone;
    [_lm startUpdatingLocation];
    [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
}
Direct access of properties should be avoided except on initialization, so self.propertyName should usually be used. In this particular case, I don't think that the location manager should even be a property, and should actually be declared in the class extension in the implementation file, as it is a private variable, not a property. This would eliminate the need to go through the accessor. The author's inconsistent use of the accessor in the initialization is sloppy. The auto generation tries to enforce the proper use of accessors which is important for proper memory management, as it does not allow you to inadvertently set a variable directly.

This should address your problem. If not send your complete, nonworking project to
ipadhelper@me.com
and I can check it out more thoroughly..

Bob
Reply With Quote
The Following User Says Thank You to thepianoguy For This Useful Post:
f_mtz (October 17th, 2013)
  #3 (permalink)  
Old October 19th, 2013, 11:59 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

Going through the project you sent me, I see that you have @synthesize declarations, that were not in the copy and paste of your original post. This will eliminate the issue that I addressed in my original reply.
I missed your annotations in the
-(void) locationManagerDidResumeLocationUpdates:(CLLocatio nManager *)manager
method.

The first issue with your implementation of this method is that you are initializing an NSString with an alertView initialization. NSString does not have an initWithTitle:message:delegate… message. You then attempted to pass the string as a the message argument, and failed to set the delegate.

This is a correct way to implement this method, with the incorrect code commented out

Code:
-(void) locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager
                              didFailWithError : (NSError *) error {
//    NSString *msg = [[NSString alloc]initWithTitle : @"Error"
//                                           message : msg
//                                          delegate : nil
//                                 cancelButtonTitle : @"Done"
//                                 otherButtonTitles : nil];
    
    NSString *msg = @"Location Update failed";
    
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                    message:msg
                                                   delegate:self
                                          cancelButtonTitle:@"Done"
                                          otherButtonTitles:nil];
   
    [alert show]; //use of undeclared identifier 'alert'
//    [message show];//use of undeclared identifier 'show'
    [alert release]; //use of undeclared identifier 'alert'
}
The NSString is initialized with the message to be displayed in the alertView.
The alertView is allocated and initialized with a title and the NSString is passed as an argument. The delegate needs to be set so that responses from the alertView can be monitored, and additional action taken if needed. As you had implemented there was no alert variable and no message variable since they were never declared, allocated or initialized. The initialization that was done which I commented out was not valid, since it is not an NSString method.
After making these corrections the program will compile without errors but will crash if you run it. Checking your storyboard, if you control-click on the view controller there are three outlets with yellow warning triangles. They need to be deleted. Also in the storyboard the three outlets that remain need to be connected to the corresponding textfields. Without these connections data generated will not be displayed.

Bob
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 20 Clever BOOK: Professional Application Lifecycle Management with Visual Studio 2010 2 January 9th, 2013 06:39 AM
Chapter 20 -- getting started OG BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 0 July 21st, 2012 03:59 PM
Getting Error 'EXEC' : undeclared identifier JAPPY Visual C++ 0 April 7th, 2004 09:35 AM
Chapter 20 masegui JSP Basics 0 April 1st, 2004 06:54 AM



All times are GMT -4. The time now is 11:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.