Skip to content

Commit b96a4af

Browse files
committed
Work around importer availability bug
1 parent 8e814ac commit b96a4af

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

stdlib/public/SDK/Foundation/Calendar.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ internal func __NSCalendarAutoupdating() -> NSCalendar
2121
@_silgen_name("__NSCalendarCurrent")
2222
internal func __NSCalendarCurrent() -> NSCalendar
2323

24+
@_silgen_name("__NSCalendarInit")
25+
internal func __NSCalendarInit(_ identifier : NSString) -> NSCalendar?
26+
2427
/**
2528
`Calendar` encapsulates information about systems of reckoning time in which the beginning, length, and divisions of a year are defined. It provides information about the calendar and support for calendrical computations such as determining the range of a given calendrical unit and adding units to a given absolute time.
2629
*/
@@ -104,7 +107,8 @@ public struct Calendar : CustomStringConvertible, CustomDebugStringConvertible,
104107
///
105108
/// - parameter identifier: The kind of calendar to use.
106109
public init(identifier: Identifier) {
107-
_handle = _MutableHandle(adoptingReference: NSCalendar(identifier: Calendar._toNSCalendarIdentifier(identifier))!)
110+
let result = __NSCalendarInit(Calendar._toNSCalendarIdentifier(identifier))!
111+
_handle = _MutableHandle(adoptingReference: result)
108112
_autoupdating = false
109113
}
110114

stdlib/public/SDK/Foundation/Thunks.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@
122122

123123
// A way to get various Calendar, Locale, and TimeZone singletons without bridging twice
124124

125+
// Unfortunately the importer does not realize that [NSCalendar initWithIdentifier:] has been around forever, and only sees the iOS 8 availability of [NSCalendar calendarWithIdentifier:].
126+
SWIFT_CC(swift)
127+
extern "C" NS_RETURNS_RETAINED NSCalendar * __nullable __NSCalendarInit(NSString * NS_RELEASES_ARGUMENT __nonnull identifier) {
128+
NSCalendar *result = [[NSCalendar alloc] initWithCalendarIdentifier:identifier];
129+
[identifier release];
130+
return result;
131+
}
132+
125133
SWIFT_CC(swift)
126134
extern "C" NS_RETURNS_RETAINED NSCalendar *__NSCalendarAutoupdating() {
127135
return [[NSCalendar autoupdatingCurrentCalendar] retain];

0 commit comments

Comments
 (0)