Skip to content

Commit 8e814ac

Browse files
committed
New value types for Calendar, TimeZone, and Locale
As part of the extensive work on value types in Foundation this year, we decided to also add value types for these three key classes. In addition to adding value semantics, the API was extensively audited to improve Swift interop (especially Calendar). rdar://26628184
1 parent 932fe9d commit 8e814ac

File tree

20 files changed

+2497
-52
lines changed

20 files changed

+2497
-52
lines changed

apinotes/Foundation.apinotes

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,15 @@ Classes:
647647
- Selector: 'stringFromByteCount:'
648648
SwiftName: stringFromByteCount(_:)
649649
MethodKind: Instance
650+
- Name: NSLocale
651+
SwiftName: NSLocale
652+
SwiftBridge: Locale
653+
- Name: NSTimeZone
654+
SwiftName: NSTimeZone
655+
SwiftBridge: TimeZone
650656
- Name: NSCalendar
657+
SwiftName: NSCalendar
658+
SwiftBridge: Calendar
651659
Methods:
652660
- Selector: 'dateWithEra:year:month:day:hour:minute:second:nanosecond:'
653661
SwiftName: date(era:year:month:day:hour:minute:second:nanosecond:)
@@ -1114,9 +1122,9 @@ Tags:
11141122
- Name: NSByteCountFormatterCountStyle
11151123
SwiftName: ByteCountFormatter.CountStyle
11161124
- Name: NSCalendarUnit
1117-
SwiftName: Calendar.Unit
1125+
SwiftName: NSCalendar.Unit
11181126
- Name: NSCalendarOptions
1119-
SwiftName: Calendar.Options
1127+
SwiftName: NSCalendar.Options
11201128
- Name: NSDecodingFailurePolicy
11211129
SwiftName: NSCoder.DecodingFailurePolicy
11221130
- Name: NSComparisonPredicateOptions
@@ -1229,7 +1237,7 @@ Tags:
12291237
Availability: nonswift
12301238
AvailabilityMsg: Use 'NSTextCheckingResult.CheckingType'
12311239
- Name: NSTimeZoneNameStyle
1232-
SwiftName: TimeZone.NameStyle
1240+
SwiftName: NSTimeZone.NameStyle
12331241
- Name: NSURLCacheStoragePolicy
12341242
SwiftName: URLCache.StoragePolicy
12351243
- Name: NSURLCredentialPersistence
@@ -1281,7 +1289,7 @@ Tags:
12811289
- Name: NSDateComponentsFormatterZeroFormattingBehavior
12821290
SwiftName: DateComponentsFormatter.ZeroFormattingBehavior
12831291
- Name: NSLocaleLanguageDirection
1284-
SwiftName: Locale.LanguageDirection
1292+
SwiftName: NSLocale.LanguageDirection
12851293
- Name: NSNetServiceOptions
12861294
SwiftName: NSNetService.Options
12871295
- Name: NSPointerFunctionsOptions
@@ -1348,13 +1356,13 @@ Typedefs:
13481356
- Name: NSBackgroundActivityCompletionHandler
13491357
SwiftName: NSBackgroundActivityScheduler.CompletionHandler
13501358
- Name: NSCalendarIdentifier
1351-
SwiftName: Calendar.Identifier
1359+
SwiftName: NSCalendar.Identifier
13521360
- Name: NSItemProviderCompletionHandler
13531361
SwiftName: NSItemProvider.CompletionHandler
13541362
- Name: NSItemProviderLoadHandler
13551363
SwiftName: NSItemProvider.LoadHandler
13561364
- Name: NSLocaleKey
1357-
SwiftName: Locale.Key
1365+
SwiftName: NSLocale.Key
13581366
- Name: NSNotificationName
13591367
SwiftName: NSNotification.Name
13601368
- Name: NSProgressFileOperationKind
@@ -1423,7 +1431,7 @@ Globals:
14231431
- Name: NSItemProviderErrorDomain
14241432
SwiftName: NSItemProvider.errorDomain
14251433
- Name: NSCurrentLocaleDidChangeNotification
1426-
SwiftName: Locale.currentLocaleDidChangeNotification
1434+
SwiftName: NSLocale.currentLocaleDidChangeNotification
14271435
- Name: NSNetServicesErrorDomain
14281436
SwiftName: NSNetService.errorDomain
14291437
- Name: NSNetServicesErrorCode

stdlib/private/StdlibUnittestFoundationExtras/StdlibUnittestFoundationExtras.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@
1313
import ObjectiveC
1414
import Foundation
1515

16-
internal var _temporaryLocaleCurrentLocale: Locale? = nil
16+
internal var _temporaryLocaleCurrentLocale: NSLocale? = nil
1717

18-
extension Locale {
18+
extension NSLocale {
1919
@objc
20-
public class func _swiftUnittest_currentLocale() -> Locale {
20+
public class func _swiftUnittest_currentLocale() -> NSLocale {
2121
return _temporaryLocaleCurrentLocale!
2222
}
2323
}
2424

2525
public func withOverriddenLocaleCurrentLocale<Result>(
26-
_ temporaryLocale: Locale,
26+
_ temporaryLocale: NSLocale,
2727
_ body: @noescape () -> Result
2828
) -> Result {
2929
let oldMethod = class_getClassMethod(
30-
Locale.self, #selector(getter: Locale.current))
30+
NSLocale.self, #selector(getter: NSLocale.current))
3131
precondition(oldMethod != nil, "could not find +[Locale currentLocale]")
3232

3333
let newMethod = class_getClassMethod(
34-
Locale.self, #selector(Locale._swiftUnittest_currentLocale))
34+
NSLocale.self, #selector(NSLocale._swiftUnittest_currentLocale))
3535
precondition(newMethod != nil, "could not find +[Locale _swiftUnittest_currentLocale]")
3636

3737
precondition(_temporaryLocaleCurrentLocale == nil,
@@ -51,11 +51,11 @@ public func withOverriddenLocaleCurrentLocale<Result>(
5151
_ body: @noescape () -> Result
5252
) -> Result {
5353
precondition(
54-
Locale.availableLocaleIdentifiers.contains(temporaryLocaleIdentifier),
54+
NSLocale.availableLocaleIdentifiers.contains(temporaryLocaleIdentifier),
5555
"requested locale \(temporaryLocaleIdentifier) is not available")
5656

5757
return withOverriddenLocaleCurrentLocale(
58-
Locale(localeIdentifier: temporaryLocaleIdentifier), body)
58+
NSLocale(localeIdentifier: temporaryLocaleIdentifier), body)
5959
}
6060

6161
/// Executes the `body` in an autorelease pool if the platform does not

stdlib/public/SDK/Foundation/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD
77
ExtraStringAPIs.swift
88
ReferenceConvertible.swift
99
AffineTransform.swift
10+
Calendar.swift
11+
TimeZone.swift
12+
Locale.swift
1013
CharacterSet.swift
1114
Date.swift
1215
DateComponents.swift

0 commit comments

Comments
 (0)