Skip to content

Commit bfc2468

Browse files
committed
Merge branch 'master' into feature/NSJSONSerialization-deserialization
2 parents 7302556 + 0254bc2 commit bfc2468

File tree

10 files changed

+52
-32
lines changed

10 files changed

+52
-32
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Contributing
22

3-
Contributions to Foundation are welcome! This project follows the [contribution guidelines for the Swift project](https://swift.org/contributing/#reporting-bugs). A few additional details are outlined below.
3+
Contributions to Foundation are welcome! This project follows the [contribution guidelines for the Swift project](https://swift.org/contributing/#contributing-code). A few additional details are outlined below.
4+
5+
## Licensing
6+
7+
By submitting a pull request, you represent that you have the right to license your contribution to Apple and the community, and agree by submitting the patch that your contributions are licensed under the [Swift license](https://swift.org/LICENSE.txt).
8+
49

510
## Bug Reports
611

Docs/Design.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ In a very limited number of cases, key Foundation API as it exists on Apple plat
1313

1414
A significant portion of the implementation of Foundation on Apple platforms is provided by another framework called CoreFoundation (a.k.a. CF). CF is written primarily in C and is very portable. Therefore we have chosen to use it for the internal implementation of Swift Foundation where possible. As CF is present on all platforms, we can use it to provide a common implementation everywhere.
1515

16+
Another aspect of portability is keeping dependencies to an absolute minimum. With fewer dependencies to port, it is more likely that Foundation will be able to easily compile and run on new platforms. Therefore, we will prefer solutions that are implemented in Foundation itself. Exceptions can be made for major functionality (for example, `ICU`, `libdispatch`, and `libxml2`).
17+
1618
## A Taxonomy of Types
1719

1820
A key to the internal design of the framework is the split between the CF implementation and Swift implementation of the Foundation classes. They can be organized into several categories.

Docs/GettingStarted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In order to build on OS X, you will need:
1212

1313
Foundation is developed at the same time as the rest of Swift, so the most recent version of the compiler is required in order to build it.
1414

15-
The repository includes an Xcode project file as well as an Xcode workspace. The workspace includes both Foundation and XCTest, which makes it easy to build and run everything together. The workspace assumes that Foundation and XCTest are checked out from GitHub in peer directories. For example:
15+
The repository includes an Xcode project file as well as an Xcode workspace. The workspace includes both Foundation and XCTest, which makes it easy to build and run everything together. The workspace assumes that Foundation and XCTest are checked out from GitHub in sibling directories. For example:
1616

1717
```
1818
% cd Development
@@ -25,7 +25,7 @@ Build and test steps:
2525

2626
0. Run Xcode with the latest toolchain. Follow [the instructions here](https://swift.org/download/#apple-platforms) to start Xcode with the correct toolchain.
2727
0. Open `Foundation.xcworkspace`.
28-
0. Build the _Foundation_ target. This builds CoreFoundation and Foundation.
28+
0. Build the _SwiftFoundation_ target. This builds CoreFoundation and Foundation.
2929
0. Run (Cmd-R) the _TestFoundation_ target. This builds CoreFoundation, Foundation, XCTest, and TestFoundation, then runs the tests.
3030

3131
> Note: If you see the name of the XCTest project file in red in the workspace, then Xcode cannot find the cloned XCTest repository. Make sure that it is located next to the `swift-corelibs-foundation` directory and has the name `swift-corelibs-xctest`.

Foundation/NSCalendar.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
365365
public func dateFromComponents(comps: NSDateComponents) -> NSDate? {
366366
var (vector, compDesc) = _convert(comps)
367367

368-
let oldTz = timeZone
369-
let tempTz = comps.timeZone
370-
if let tz = tempTz {
371-
timeZone = tz
372-
}
368+
self.timeZone = comps.timeZone ?? timeZone
373369

374370
var at: CFAbsoluteTime = 0.0
375371
let res: Bool = withUnsafeMutablePointer(&at) { t in
@@ -378,15 +374,11 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
378374
}
379375
}
380376

381-
if tempTz != nil {
382-
self.timeZone = oldTz
383-
}
384-
385377
if res {
386378
return NSDate(timeIntervalSinceReferenceDate: at)
379+
} else {
380+
return nil
387381
}
388-
389-
return nil
390382
}
391383

392384
private func _setup(unitFlags: NSCalendarUnit, field: NSCalendarUnit, type: String, inout compDesc: [Int8]) {

Foundation/NSFileManager.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,13 @@ public class NSFileManager : NSObject {
211211

212212
This method replaces fileAttributesAtPath:traverseLink:.
213213
*/
214-
public func attributesOfItemAtPath(path: String) throws -> [String : AnyObject] {
214+
/// - Experiment: Note that the return type of this function is different than on Darwin Foundation (Any instead of AnyObject). This is likely to change once we have a more complete story for bridging in place.
215+
public func attributesOfItemAtPath(path: String) throws -> [String : Any] {
215216
var s = stat()
216217
guard lstat(path, &s) == 0 else {
217218
throw _NSErrorWithErrno(errno, reading: true, path: path)
218219
}
219-
var result = [String : AnyObject]()
220+
var result = [String : Any]()
220221
result[NSFileSize] = NSNumber(unsignedLongLong: UInt64(s.st_size))
221222

222223
#if os(OSX) || os(iOS)
@@ -233,14 +234,14 @@ public class NSFileManager : NSObject {
233234

234235
let pwd = getpwuid(s.st_uid)
235236
if pwd != nil && pwd.memory.pw_name != nil {
236-
if let name = NSString(bytes: pwd.memory.pw_name, length: Int(strlen(pwd.memory.pw_name)), encoding: NSUTF8StringEncoding) {
237+
if let name = String.fromCString(pwd.memory.pw_name) {
237238
result[NSFileOwnerAccountName] = name
238239
}
239240
}
240241

241242
let grd = getgrgid(s.st_gid)
242243
if grd != nil && grd.memory.gr_name != nil {
243-
if let name = NSString(bytes: grd.memory.gr_name, length: Int(strlen(grd.memory.gr_name)), encoding: NSUTF8StringEncoding) {
244+
if let name = String.fromCString(grd.memory.gr_name) {
244245
result[NSFileGroupOwnerAccountID] = name
245246
}
246247
}
@@ -255,7 +256,7 @@ public class NSFileManager : NSObject {
255256
case S_IFSOCK: type = NSFileTypeSocket
256257
default: type = NSFileTypeUnknown
257258
}
258-
result[NSFileType] = NSString(type)
259+
result[NSFileType] = type
259260

260261
if type == NSFileTypeBlockSpecial || type == NSFileTypeCharacterSpecial {
261262
result[NSFileDeviceIdentifier] = NSNumber(unsignedLongLong: UInt64(s.st_rdev))

Foundation/NSIndexPath.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ public class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
1515
_indexes = []
1616
}
1717
public init(indexes: UnsafePointer<Int>, length: Int) {
18-
_indexes = []
19-
for var idx = 0; idx < length; idx++ {
20-
_indexes.append(indexes[idx])
21-
}
18+
_indexes = Array(UnsafeBufferPointer(start: indexes, count: length))
2219
}
2320

2421
private init(indexes: [Int]) {

Foundation/NSIndexSet.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,10 @@ public class NSMutableIndexSet : NSIndexSet {
484484
}
485485

486486
public func addIndex(value: Int) {
487-
// TODO: Bounds checking
488487
self.addIndexesInRange(NSMakeRange(value, 1))
489488
}
490489

491490
public func removeIndex(value: Int) {
492-
// TODO: Bounds checking
493491
self.removeIndexesInRange(NSMakeRange(value, 1))
494492
}
495493

Foundation/NSURLError.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
@discussion Constants used by NSError to differentiate between "domains" of error codes, serving as a discriminator for error codes that originate from different subsystems or sources.
1313
@constant NSURLErrorDomain Indicates an NSURL error.
1414
*/
15-
public let NSURLErrorDomain: String = "" // NSUnimplemented
15+
public let NSURLErrorDomain: String = "NSURLErrorDomain"
1616

1717
/*!
1818
@const NSURLErrorFailingURLErrorKey
1919
@abstract The NSError userInfo dictionary key used to store and retrieve the URL which caused a load to fail.
2020
*/
21-
public let NSURLErrorFailingURLErrorKey: String = "" // NSUnimplemented
21+
public let NSURLErrorFailingURLErrorKey: String = "NSErrorFailingURLKey"
2222

2323
/*!
2424
@const NSURLErrorFailingURLStringErrorKey
2525
@abstract The NSError userInfo dictionary key used to store and retrieve the NSString object for the URL which caused a load to fail.
2626
@discussion This constant supersedes NSErrorFailingURLStringKey, which was deprecated in Mac OS X 10.6. Both constants refer to the same value for backward-compatibility, but this symbol name has a better prefix.
2727
*/
28-
public let NSURLErrorFailingURLStringErrorKey: String = "" // NSUnimplemented
28+
public let NSURLErrorFailingURLStringErrorKey: String = "NSErrorFailingURLStringKey"
2929

3030
/*!
3131
@const NSErrorFailingURLStringKey
@@ -37,14 +37,14 @@ public let NSURLErrorFailingURLStringErrorKey: String = "" // NSUnimplemented
3737
@const NSURLErrorFailingURLPeerTrustErrorKey
3838
@abstract The NSError userInfo dictionary key used to store and retrieve the SecTrustRef object representing the state of a failed SSL handshake.
3939
*/
40-
public let NSURLErrorFailingURLPeerTrustErrorKey: String = "" // NSUnimplemented
40+
public let NSURLErrorFailingURLPeerTrustErrorKey: String = "NSURLErrorFailingURLPeerTrustErrorKey"
4141

4242
/*!
4343
@const NSURLErrorBackgroundTaskCancelledReasonKey
4444
@abstract The NSError userInfo dictionary key used to store and retrieve the NSNumber corresponding to the reason why a background
4545
NSURLSessionTask was cancelled
4646
*/
47-
public let NSURLErrorBackgroundTaskCancelledReasonKey: String = "" // NSUnimplemented
47+
public let NSURLErrorBackgroundTaskCancelledReasonKey: String = "NSURLErrorBackgroundTaskCancelledReasonKey"
4848

4949
/*!
5050
@enum Codes associated with NSURLErrorBackgroundTaskCancelledReasonKey

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ In our first year, we are not looking to make major API changes to the library.
2424

2525
### API Naming and Foundation
2626

27-
One of the goals of the Swift 3 project is [a new set of naming guidelines](https://swift.org/documentation/api-design-guidelines.html). The Foundation project will soon update all of its names to match the new guidelines. We will also drop the 'NS' prefix from all classes.
27+
One of the goals of the Swift 3 project is [a new set of naming guidelines](https://swift.org/documentation/api-design-guidelines.html). The Foundation project will soon update all of its names to match the new guidelines. We will also drop the 'NS' prefix from all Foundation classes.
2828

2929
### Current Status
3030

TestFoundation/TestNSFileManager.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,33 @@ class TestNSFileManger : XCTestCase {
9696

9797
do {
9898
let attrs = try fm.attributesOfItemAtPath(path)
99-
// TODO: Actually verify the contents of the dictionary.
99+
100100
XCTAssertTrue(attrs.count > 0)
101+
102+
let fileSize = attrs[NSFileSize] as? NSNumber
103+
XCTAssertEqual(fileSize!.longLongValue, 0)
104+
105+
let fileModificationDate = attrs[NSFileModificationDate] as? NSDate
106+
XCTAssertGreaterThan(NSDate().timeIntervalSince1970, fileModificationDate!.timeIntervalSince1970)
107+
108+
let filePosixPermissions = attrs[NSFilePosixPermissions] as? NSNumber
109+
XCTAssertNotEqual(filePosixPermissions!.longLongValue, 0)
110+
111+
let fileReferenceCount = attrs[NSFileReferenceCount] as? NSNumber
112+
XCTAssertEqual(fileReferenceCount!.longLongValue, 1)
113+
114+
let fileSystemNumber = attrs[NSFileSystemNumber] as? NSNumber
115+
XCTAssertNotEqual(fileSystemNumber!.longLongValue, 0)
116+
117+
let fileSystemFileNumber = attrs[NSFileSystemFileNumber] as? NSNumber
118+
XCTAssertNotEqual(fileSystemFileNumber!.longLongValue, 0)
119+
120+
let fileType = attrs[NSFileType] as? String
121+
XCTAssertEqual(fileType!, NSFileTypeRegular)
122+
123+
let fileOwnerAccountID = attrs[NSFileOwnerAccountID] as? NSNumber
124+
XCTAssertNotEqual(fileOwnerAccountID!.longLongValue, 0)
125+
101126
} catch let err {
102127
XCTFail("\(err)")
103128
}

0 commit comments

Comments
 (0)