Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6043347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:53:26+00:00 2026-05-23T06:53:26+00:00

Someone please help. I am a noob here who has just created an array

  • 0

Someone please help.

I am a noob here who has just created an array to contain all my polyclinics object. Now I need to add in a user object (patientDetail object) into this array. But no matter how i modify the viewDidLoad method, something just seems not quite right.. i cannot populate all the points.. only when i remove all codes that deal with the user object then it works.. Some1 please take a look at the method below and advise? I need to add in the patientDetail object and populate it with the rest of the polyclinics…

thanks for reading =(

- (void)viewDidLoad {
        [super viewDidLoad];

        _annotation2 = [[NSMutableArray alloc] init];

    CLLocation *userLoc = _mapView.userLocation.location;
        CLLocationCoordinate2D userCoordinate = userLoc.coordinate;

    NSLog(@"user latitude = %f",userCoordinate.latitude);
    NSLog(@"user longitude = %f",userCoordinate.longitude);



   _annotations=[[NSMutableArray alloc] init];
       _listOfPolyClinics = [[NSMutableArray alloc] init];

PatientDetails *patientDetails = [[PatientDatabase database] 
                                  patientDetails:_nric];

for (PolyClinics *polyclinics in [[PatientDatabase database] 
                                  polyClinics]){
    [_listOfPolyClinics addObject:polyclinics];
}

[_listOfPolyClinics addObject:patientDetails];



for (PolyClinics *polyclinics1 in _listOfPolyClinics){
    MyAnnotation* myAnnotation=[[MyAnnotation alloc] init];

    if ([polyclinics1 isKindOfClass:[PatientDetails class]]){ 
        CLLocationCoordinate2D theCoordinate3;
        theCoordinate3.longitude = patientDetails.longitude;
        theCoordinate3.latitude = patientDetails.latitude;

        myAnnotation.coordinate = theCoordinate3;
        myAnnotation.title = _nric;
        myAnnotation.subtitle = [NSString        stringWithFormat:@"%i",patientDetails.category];

    }    
    else{
    CLLocationCoordinate2D theCoordinate;
    theCoordinate.longitude = polyclinics1.longtitude;
    NSLog(@"Halo");
    theCoordinate.latitude = polyclinics1.latitude;
    NSLog(@"bye");


    //myAnnotation.pinColor = MKPinAnnotationColorPurple;
    myAnnotation.coordinate = theCoordinate;
    myAnnotation.title = polyclinics1.name;
    myAnnotation.subtitle = [NSString stringWithFormat:@"%i",polyclinics1.telephone];
    }
    [_mapView addAnnotation:myAnnotation];
    [_annotation2 addObject:myAnnotation];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:53:27+00:00Added an answer on May 23, 2026 at 6:53 am

    Because you have different classes in your array you can’t use for (PolyClinics *polyclinics1 in _listOfPolyClinics)to iterate over the array. Use idinstead, then ask the object of what class it is and then cast it to that class if you have to.

    Try to change your second for loop to

    for (id polyclinics1 in _listOfPolyClinics){
        MyAnnotation* myAnnotation=[[MyAnnotation alloc] init];
    
        if ([polyclinics1 isKindOfClass:[PatientDetails class]]){ 
            CLLocationCoordinate2D theCoordinate3;
            theCoordinate3.longitude = patientDetails.longitude;
            theCoordinate3.latitude = patientDetails.latitude;
    
            myAnnotation.coordinate = theCoordinate3;
            myAnnotation.title = _nric;
            myAnnotation.subtitle = [NSString stringWithFormat:@"%i",patientDetails.category];
        } else {
            CLLocationCoordinate2D theCoordinate;
            PolyClinics *polyclinic = (PolyClinics *)polyclinics1;
            theCoordinate.longitude = polyclinic.longtitude;
            NSLog(@"Halo");
            theCoordinate.latitude = polyclinic.latitude;
            NSLog(@"bye");
    
            //myAnnotation.pinColor = MKPinAnnotationColorPurple;
            myAnnotation.coordinate = theCoordinate;
            myAnnotation.title = polyclinic.name;
            myAnnotation.subtitle = [NSString stringWithFormat:@"%i",polyclinic.telephone];
        }
        [_mapView addAnnotation:myAnnotation];
        [_annotation2 addObject:myAnnotation];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently written this with help from SO. Now could someone please tell me
Please can someone help sort a noob out? I've posted this problem on various
Could someone please help me to understand how to get all parameters passed to
Could someone please help with the following jQuery I need all jQuery UI buttons
Can someone please help me out, I am just getting into Spring3, Spring3 MVC
Can someone please help me out with printing the contents of an IFrame via
Someone please help. I have an interesting issue. I am trying to implement an
Someone please help me understand why this binding does not work... I have a
Can someone please help me to force my website to redirect to using www.
Could someone please help me understand that why am I getting this error at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.