我正在努力学习如何将目标C与swift结合起来。在这个例子中,我希望coord2d在swift中是可选的,因此生成的swift块看起来像:
photoPicker.cropBlock = { (coord2d: CLLocationCoordinate2D?) -> () in
以下是它现在看起来如何--- coor2d不是可选的,而只是为coord2d.latitude和coord2d.longitude返回0
//.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