struct Date
is the "Swift overlay type" to the Foundation type
NSDate
(compare Swift 3: Date vs NSDate?) and unknown to Objective-C.
You'll have to define an extension to NSDate
in order
to be useable from Objective-C:
extension NSDate {
static func getDefaultFormattedDateStringFromDate(_ validToDate: Date) -> String? {
// ...
}
}
This is imported to Objective-C as
@interface NSDate
+ (NSString * _Nullable)getDefaultFormattedDateStringFromDate:(NSDate * _Nonnull)validToDate;
@end
Note that the parameter and return types (Date
, String
) are automatically bridged to the Foundation types (NSDate
, NSString
).
All this is unrelated to static (type) vs instance methods, and in
your case it might be more "natural" to define an instance
method:
extension NSDate {
func defaultFormattedString() -> String? {
// ...
}
}
which is imported to Objective-C as
@interface NSDate
- (NSString * _Nullable)defaultFormattedString;
@end
and called as
NSString *dateString = [[NSDate date] defaultFormattedString];