作者:wszr12345597 | 来源:互联网 | 2023-08-04 13:55
ForsomereasonthelocationpropertyonaPHAssetisonlyexposedinObjective-candnotinSwift.
For some reason the location
property on a PHAsset
is only exposed in Objective-c and not in Swift.
由于某种原因,PHAsset上的location属性仅在Objective-c中公开,而不在Swift中公开。
Documentation: PHAsset.location
To work around it, I figured I could create a Objective-C class whose sole purpose is to extract the location and import it into Swift.
为了解决这个问题,我想我可以创建一个Objective-C类,其唯一目的是提取位置并将其导入Swift。
LocationGetter.h
@interface LocationGetter : NSObject
+ (CLLocation *)locationForAsset:(PHAsset *) asset;
@end
LocationGetter.m
@implementation LocationGetter
+ (CLLocation *)locationForAsset:(PHAsset *) asset {
return [asset location];
}
@end
So far so good, but when I try to use it in Swift:
到目前为止一切都那么好,但是当我尝试在Swift中使用它时:
LocationGetter.locationForAsset(ass)
'LocationGetter.Type' does not have a member named 'locationForAsset'
'LocationGetter.Type'没有名为'locationForAsset'的成员
Bonus question: Why on earth didn't Apple expose location
in swift?
奖金问题:为什么Apple没有公开位置?
2 个解决方案