-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement -[NSData writeToURL:options:error:] #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,10 @@ | |
|
||
|
||
/*************** Exceptions ***********/ | ||
public let NSDecimalNumberExactnessException: String = "" // NSUnimplemented | ||
public let NSDecimalNumberOverflowException: String = "" // NSUnimplemented | ||
public let NSDecimalNumberUnderflowException: String = "" // NSUnimplemented | ||
public let NSDecimalNumberDivideByZeroException: String = "" // NSUnimplemented | ||
public let NSDecimalNumberExactnessException: String = "NSDecimalNumberExactnessException" | ||
public let NSDecimalNumberOverflowException: String = "NSDecimalNumberOverflowException" | ||
public let NSDecimalNumberUnderflowException: String = "NSDecimalNumberUnderflowException" | ||
public let NSDecimalNumberDivideByZeroException: String = "NSDecimalNumberDivideByZeroException" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are not exactly part of NSData's url writing, it would be good to split them out to their own commits There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the one below |
||
|
||
/*************** Rounding and Exception behavior ***********/ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,8 @@ | |
// | ||
|
||
|
||
public let NSDefaultRunLoopMode: String = "" // NSUnimplemented | ||
public let NSRunLoopCommonModes: String = "" // NSUnimplemented | ||
public let NSDefaultRunLoopMode: String = "NSDefaultRunLoopMode" | ||
public let NSRunLoopCommonModes: String = "NSRunLoopCommonModes" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These probably will need to be the same as their CF counterparts when run loops will be supported. |
||
|
||
public class NSRunLoop : NSObject { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
|
||
|
||
|
||
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux) | ||
import Foundation | ||
import XCTest | ||
#else | ||
import SwiftFoundation | ||
import SwiftXCTest | ||
#endif | ||
|
||
|
||
|
||
class TestNSData : XCTestCase { | ||
|
||
var allTests : [(String, () -> ())] { | ||
return [ | ||
("test_writeToURLOptions", test_writeToURLOptions) | ||
] | ||
} | ||
|
||
func test_writeToURLOptions() { | ||
let saveData = NSData(contentsOfURL: NSBundle.mainBundle().URLForResource("Test", withExtension: "plist")!) | ||
let savePath = "/var/tmp/Test.plist" | ||
do { | ||
try saveData!.writeToFile(savePath, options: NSDataWritingOptions.DataWritingAtomic) | ||
let fileManager = NSFileManager.defaultManager() | ||
XCTAssertTrue(fileManager.fileExistsAtPath(savePath)) | ||
try! fileManager.removeItemAtPath(savePath) | ||
} catch let error { | ||
XCTFail((error as! NSError).localizedDescription) | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,5 @@ XCTMain([ | |
TestNSFileManger(), | ||
TestNSRange(), | ||
TestNSXMLParser(), | ||
TestNSData() | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that the error message also isn't quite correct about the first part. You aren't checking whether a folder exist, but wether the URL given contains a path. (But I am not sure exactly what the existing Foundation framework does/reports in this case.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the url is a file url then it checks to see if the url has a path, if it does not it claims there is no such file (which is kind-of true-ish)
then it will funnel to writeToFile in the case of a file url (which has it's own error cases)
else it claims the url is an unsupported scheme.