Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to load plist and pass string Array polygons under NSDictionary?
    primarykey
    data
    text
    <p>I am trying to load data.plist string array polygons under NSDictionary(ex. +40.48675,-60.434543) to building. I have 6 index in array. I keep getting warning "Passing argument 7 of initWithID:name:code:number:location:description:polygons from incompatible pointer type." Also the draw polygon doesnt show on map. What ami I missing?</p> <pre><code>NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; NSArray *array = [[[NSArray alloc] initWithContentsOfFile:path] objectAtIndex:0]; buildings = [[NSMutableArray alloc] init]; for(int i = 0; i &lt; [array count]; i++) { NSMutableDictionary *dic = [array objectAtIndex:i]; NSString *buildingID = [dic objectForKey:@"buildingID"]; NSString *name = [dic objectForKey:@"name"]; NSString *code = [dic objectForKey:@"code"]; NSString *number = [dic objectForKey:@"number"]; //NSString *location = [dic objectForKey:@"location"]; NSString *description = [dic objectForKey:@"description"]; //NSArray *components = [location componentsSeparatedByString:@","]; //NSString *latitude = [components objectAtIndex:0]; //NSString *longitude = [components objectAtIndex:1]; NSArray *polygons = [[NSArray alloc] init]; polygons = [dic objectForKey:@"polygons"]; int countPoints = [self.polygons count]; CLLocationCoordinate2D buildingPoly[countPoints]; for (int i = 0; i &lt; countPoints; i++) { NSArray *splitArrayPoly = [[polygons objectAtIndex:i] componentsSeparatedByString:@","]; buildingPoly[i] = CLLocationCoordinate2DMake([[splitArrayPoly objectAtIndex:0] floatValue], [[splitArrayPoly objectAtIndex:1] floatValue]); } NSArray *splitArray = [ [dic objectForKey:@"location"] componentsSeparatedByString:@","]; float latitude = [[splitArray objectAtIndex:0]floatValue]; float longitude = [[splitArray objectAtIndex:1]floatValue]; CLLocation *tempLocation = [[[CLLocation alloc] initWithLatitude:latitude longitude:longitude]autorelease]; Building *building = [[[Building alloc] initWithID:[buildingID intValue] name:name code:code number:number location:tempLocation description:description polygons:buildingPoly]autorelease]; //This is where I got warning //building.polygons = polygons; // delete this when ure done with init //NSLog(@"building.polygons = %@", building.polygons); // ask teacher about this [buildings addObject:building]; [dic release]; [building release]; } </code></pre> <p>Then in different class "Building.m" it pass polygons to here</p> <pre><code>- (id)initWithID:(int)b_id name:(NSString *)b_name code:(NSString *)b_code number:(NSString *)b_number location:(CLLocation *)b_location description:(NSString *)b_description polygons:(NSArray *)b_polygons { self = [super init]; if (self != nil) { self.buildingID = b_id; self.name = b_name; self.location = b_location; self.code = b_code; self.number = b_number; self.description = b_description; self.polygons = b_polygons; } return self; } </code></pre> <p>Then this method should get all polygons and make it on map. However it doesn't show anything.</p> <pre><code>- (MKPolygon *)getPolygons{ int countPoints = [self.polygons count]; CLLocationCoordinate2D building[countPoints]; for (int i = 0; i &lt; countPoints; i++) { NSArray *splitArray = [[polygons objectAtIndex:i] componentsSeparatedByString:@","]; building[i] = CLLocationCoordinate2DMake([[splitArray objectAtIndex:0] floatValue], [[splitArray objectAtIndex:1] floatValue]); } return [MKPolygon polygonWithCoordinates:building count:countPoints]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload