Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Swift 4.2 Support #31

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0
28 changes: 27 additions & 1 deletion rebekka-demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = "Constantine Fry";
TargetAttributes = {
47FFC2A51B09287300D3EDFE = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 1000;
};
};
};
Expand Down Expand Up @@ -265,13 +266,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -310,13 +321,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -335,6 +356,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -347,6 +369,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.fry.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -358,6 +382,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.fry.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
20 changes: 10 additions & 10 deletions rebekka-demo/Demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

var configuration = SessionConfiguration()
Expand All @@ -36,27 +36,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func testList() {
self.session.list("/") {
(resources, error) -> Void in
print("List directory with result:\n\(resources), error: \(error)\n\n")
print("List directory with result:\n\(resources!), error: \(error!)\n\n")
}
}

func testUpload() {
if let URL = NSBundle.mainBundle().URLForResource("TestUpload", withExtension: "png") {
let path = "/upload/\(NSUUID().UUIDString).png"
if let URL = Bundle.main.url(forResource: "TestUpload", withExtension: "png") {
let path = "/upload/\(UUID().uuidString).png"
self.session.upload(URL, path: path) {
(result, error) -> Void in
print("Upload file with result:\n\(result), error: \(error)\n\n")
print("Upload file with result:\n\(result), error: \(error!)\n\n")
}
}
}

func testDownload() {
self.session.download("/1MB.zip") {
(fileURL, error) -> Void in
print("Download file with result:\n\(fileURL), error: \(error)\n\n")
print("Download file with result:\n\(fileURL!), error: \(error!)\n\n")
if let fileURL = fileURL {
do {
try NSFileManager.defaultManager().removeItemAtURL(fileURL)
try FileManager.default.removeItem(at: fileURL)
} catch let error as NSError {
print("Error: \(error)")
}
Expand All @@ -66,10 +66,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func testCreate() {
let name = NSUUID().UUIDString
let name = UUID().uuidString
self.session.createDirectory("/upload/\(name)") {
(result, error) -> Void in
print("Create directory with result:\n\(result), error: \(error)")
print("Create directory with result:\n\(result), error: \(error!)")
}
}

Expand Down
33 changes: 32 additions & 1 deletion rebekka-source/Rebekka.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,16 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = "Constantine Fry";
TargetAttributes = {
47FFC2821B09279200D3EDFE = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
};
47FFC2DB1B09297E00D3EDFE = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 1000;
};
};
};
Expand Down Expand Up @@ -313,13 +315,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -362,13 +374,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -388,6 +410,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -419,6 +442,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -440,13 +464,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
47FFC2F01B09297E00D3EDFE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -463,13 +489,16 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
47FFC2F11B09297E00D3EDFE /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -481,6 +510,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "net.fry.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
26 changes: 13 additions & 13 deletions rebekka-source/Rebekka/FileDownloadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,48 @@ import Foundation
/** Operation for downloading a file from FTP server. */
internal class FileDownloadOperation: ReadStreamOperation {

private var fileHandle: NSFileHandle?
var fileURL: NSURL?
private var fileHandle: FileHandle?
var fileURL: URL?

override func start() {
let filePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent(NSUUID().UUIDString)
self.fileURL = NSURL(fileURLWithPath: filePath)
let filePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(UUID().uuidString)
self.fileURL = URL(fileURLWithPath: filePath)
do {
try NSData().writeToURL(self.fileURL!, options: NSDataWritingOptions.DataWritingAtomic)
self.fileHandle = try NSFileHandle(forWritingToURL: self.fileURL!)
try Data().write(to: self.fileURL!, options: NSData.WritingOptions.atomic)
self.fileHandle = try FileHandle(forWritingTo: self.fileURL!)
self.startOperationWithStream(self.readStream)
} catch let error as NSError {
self.error = error
self.finishOperation()
}
}

override func streamEventEnd(aStream: NSStream) -> (Bool, NSError?) {
override func streamEventEnd(_ aStream: Stream) -> (Bool, NSError?) {
self.fileHandle?.closeFile()
return (true, nil)
}

override func streamEventError(aStream: NSStream) {
override func streamEventError(_ aStream: Stream) {
super.streamEventError(aStream)
self.fileHandle?.closeFile()
if self.fileURL != nil {
do {
try NSFileManager.defaultManager().removeItemAtURL(self.fileURL!)
try FileManager.default.removeItem(at: self.fileURL!)
} catch _ {
}
}
self.fileURL = nil
}

override func streamEventHasBytes(aStream: NSStream) -> (Bool, NSError?) {
if let inputStream = aStream as? NSInputStream {
override func streamEventHasBytes(_ aStream: Stream) -> (Bool, NSError?) {
if let inputStream = aStream as? InputStream {
var parsetBytes: Int = 0
repeat {
parsetBytes = inputStream.read(self.temporaryBuffer, maxLength: 1024)
if parsetBytes > 0 {
autoreleasepool {
let data = NSData(bytes: self.temporaryBuffer, length: parsetBytes)
self.fileHandle!.writeData(data)
let data = Data(bytes: UnsafePointer<UInt8>(self.temporaryBuffer), count: parsetBytes)
self.fileHandle!.write(data)
}
}
} while (parsetBytes > 0)
Expand Down
20 changes: 10 additions & 10 deletions rebekka-source/Rebekka/FileUploadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Foundation

/** Operation for file uploading. */
internal class FileUploadOperation: WriteStreamOperation {
private var fileHandle: NSFileHandle?
var fileURL: NSURL!
fileprivate var fileHandle: FileHandle?
var fileURL: URL!

override func start() {
do {
self.fileHandle = try NSFileHandle(forReadingFromURL: fileURL)
self.fileHandle = try FileHandle(forReadingFrom: fileURL)
self.startOperationWithStream(self.writeStream)
} catch let error as NSError {
self.error = error
Expand All @@ -24,23 +24,23 @@ internal class FileUploadOperation: WriteStreamOperation {
}
}

override func streamEventEnd(aStream: NSStream) -> (Bool, NSError?) {
override func streamEventEnd(_ aStream: Stream) -> (Bool, NSError?) {
self.fileHandle?.closeFile()
return (true, nil)
}

override func streamEventError(aStream: NSStream) {
override func streamEventError(_ aStream: Stream) {
super.streamEventError(aStream)
self.fileHandle?.closeFile()
}

override func streamEventHasSpace(aStream: NSStream) -> (Bool, NSError?) {
if let writeStream = aStream as? NSOutputStream {
override func streamEventHasSpace(_ aStream: Stream) -> (Bool, NSError?) {
if let writeStream = aStream as? OutputStream {
let offsetInFile = self.fileHandle!.offsetInFile
let data = self.fileHandle!.readDataOfLength(1024)
let writtenBytes = writeStream.write(UnsafePointer<UInt8>(data.bytes), maxLength: data.length)
let data = self.fileHandle!.readData(ofLength: 1024)
let writtenBytes = writeStream.write((data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count), maxLength: data.count)
if writtenBytes > 0 {
self.fileHandle?.seekToFileOffset(offsetInFile + UInt64(writtenBytes))
self.fileHandle?.seek(toFileOffset: offsetInFile + UInt64(writtenBytes))
} else if writtenBytes == -1 {
self.finishOperation()
}
Expand Down
Loading