2

I'm trying to learn how to combine objective C with swift. In this example I want coord2d to be an optional in swift, so the resulting swift block looks like:

photoPicker.cropBlock = { (coord2d: CLLocationCoordinate2D?) -> () in

Here's how it looks right now though --- coor2d is not an optional, and instead just return 0 for coord2d.latitude and coord2d.longitude

//.h
@property (nonatomic, copy) void(^cropBlock)(CLLocationCoordinate2D coord2D);


//.m
- (void)cropAction {
    if (self.cropBlock) {
        NSDictionary * dict = photoSelected.asset.defaultRepresentation.metadata[@"{GPS}"];
        CLLocationCoordinate2D coord;
        coord.longitude = (CLLocationDegrees)[[dict objectForKey:@"Longitude"] floatValue];
        coord.latitude = (CLLocationDegrees)[[dict objectForKey:@"Latitude"] floatValue];

        self.cropBlock(coord);

    }
}

//ViewController.swift
photoPicker.cropBlock = { (coord2d: CLLocationCoordinate2D) -> () in
Mike Jonas
  • 333
  • 1
  • 4
  • 12

0 Answers0