Skip to content
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

Initial Swift 3 compatibility #27

Merged
merged 6 commits into from
Aug 18, 2016
Merged
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
3 changes: 2 additions & 1 deletion FileKit.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Use this playground to try out FileKit
import Cocoa
import FileKit
import XCPlayground
import PlaygroundSupport

extension Path {
static let SharedPlaygroundData = Path(url: XCPlaygroundSharedDataDirectoryURL)!
static let SharedPlaygroundData = Path(url: playgroundSharedDataDirectory)!
}

let shared = Path.SharedPlaygroundData
Expand Down
13 changes: 9 additions & 4 deletions FileKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
52BF6BB21B99322000F07E13 /* FileKitError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BF6BB01B99322000F07E13 /* FileKitError.swift */; };
82F4F2BD1CA95480002C8393 /* FileSystemWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F4F2BC1CA95480002C8393 /* FileSystemWatcher.swift */; };
82F4F2C01CA956F2002C8393 /* FileSystemEventStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F4F2BF1CA956F2002C8393 /* FileSystemEventStream.swift */; };
C404F01E1BC7CA7200EF9ED9 /* Date+FileKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = C404F01D1BC7CA7200EF9ED9 /* Date+FileKit.swift */; };
C4F7D01F1C08C0DA00EF359B /* FileSystemEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F7D01E1C08C0DA00EF359B /* FileSystemEvent.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -168,7 +167,6 @@
82F4F2BB1CA94DEC002C8393 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = "<group>"; };
82F4F2BC1CA95480002C8393 /* FileSystemWatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileSystemWatcher.swift; sourceTree = "<group>"; };
82F4F2BF1CA956F2002C8393 /* FileSystemEventStream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileSystemEventStream.swift; sourceTree = "<group>"; };
C404F01D1BC7CA7200EF9ED9 /* Date+FileKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Date+FileKit.swift"; sourceTree = "<group>"; };
C4F7D01E1C08C0DA00EF359B /* FileSystemEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileSystemEvent.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -269,7 +267,6 @@
isa = PBXGroup;
children = (
5263A9061B96BA3D00635A93 /* FileKitTests.swift */,
C404F01D1BC7CA7200EF9ED9 /* Date+FileKit.swift */,
5263A9081B96BA3D00635A93 /* Info.plist */,
);
path = Tests;
Expand Down Expand Up @@ -455,12 +452,15 @@
TargetAttributes = {
5204B84A1B96B83800AA473F = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
5204B8571B96B85E00AA473F = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
5263A9031B96BA3D00635A93 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
527612411BAEA3EE00503D0A = {
CreatedOnToolsVersion = 7.0;
Expand Down Expand Up @@ -662,7 +662,6 @@
buildActionMask = 2147483647;
files = (
5263A9071B96BA3D00635A93 /* FileKitTests.swift in Sources */,
C404F01E1BC7CA7200EF9ED9 /* Date+FileKit.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -850,6 +849,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.nikolaivazquez.$(PROJECT_NAME)";
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -869,6 +869,7 @@
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -887,6 +888,7 @@
PRODUCT_NAME = "$(PROJECT_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -907,6 +909,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -920,6 +923,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nikolaivazquez.FileKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -932,6 +936,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.nikolaivazquez.FileKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
12 changes: 6 additions & 6 deletions Sources/DataFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ extension File where Data: NSData {

/// Reads the file and returns its data.
/// - Parameter options: A mask that specifies write options
/// described in `NSDataReadingOptions`.
/// described in `NSData.ReadingOptions`.
///
/// - Throws: `FileKitError.ReadFromFileFail`
/// - Returns: The data read from file.
public func read(options: NSDataReadingOptions) throws -> Data {
public func read(_ options: NSData.ReadingOptions) throws -> Data {
return try Data.readFromPath(path, options: options)
}

/// Writes data to the file.
///
/// - Parameter data: The data to be written to the file.
/// - Parameter options: A mask that specifies write options
/// described in `NSDataWritingOptions`.
/// described in `NSData.WritingOptions`.
///
/// - Throws: `FileKitError.WriteToFileFail`
///
public func write(data: Data, options: NSDataWritingOptions) throws {
public func write(_ data: Data, options: NSData.WritingOptions) throws {
do {
try data.writeToFile(self.path._safeRawValue, options: options)
try data.write(toFile: self.path._safeRawValue, options: options)
} catch {
throw FileKitError.WriteToFileFail(path: path)
throw FileKitError.writeToFileFail(path: self.path)
}
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/DataType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import Foundation

/// A type that can be used to read from and write to File instances.
public typealias DataType = protocol<Readable, Writable>
public typealias DataType = Readable & Writable



Expand All @@ -39,7 +39,7 @@ public protocol Readable {
///
/// - Parameter path: The path being read from.
///
static func readFromPath(path: Path) throws -> Self
static func readFromPath(_ path: Path) throws -> Self

}

Expand All @@ -61,7 +61,7 @@ extension Readable {
public protocol Writable {

/// Writes `self` to a Path.
func writeToPath(path: Path) throws
func writeToPath(_ path: Path) throws

/// Writes `self` to a Path.
///
Expand All @@ -71,7 +71,7 @@ public protocol Writable {
/// file. If `false`, the data is written to
/// the file directly.
///
func writeToPath(path: Path, atomically useAuxiliaryFile: Bool) throws
func writeToPath(_ path: Path, atomically useAuxiliaryFile: Bool) throws

}

Expand All @@ -81,7 +81,7 @@ extension Writable {
///
/// - Parameter path: The path being written to.
///
public func writeToPath(path: Path) throws { // swiftlint:disable:this valid_docs
public func writeToPath(_ path: Path) throws { // swiftlint:disable:this valid_docs
try writeToPath(path, atomically: true)
}

Expand All @@ -101,7 +101,7 @@ public protocol WritableToFile: Writable {
/// - Returns: `true` if the writing completed successfully, or `false` if
/// the writing failed.
///
func writeToFile(path: String, atomically useAuxiliaryFile: Bool) -> Bool
func writeToFile(_ path: String, atomically useAuxiliaryFile: Bool) -> Bool

}

Expand All @@ -119,9 +119,9 @@ extension WritableToFile {
///
/// - Throws: `FileKitError.WriteToFileFail`
///
public func writeToPath(path: Path, atomically useAuxiliaryFile: Bool) throws {
public func writeToPath(_ path: Path, atomically useAuxiliaryFile: Bool) throws {
guard writeToFile(path._safeRawValue, atomically: useAuxiliaryFile) else {
throw FileKitError.WriteToFileFail(path: path)
throw FileKitError.writeToFileFail(path: path)
}
}

Expand Down Expand Up @@ -154,7 +154,7 @@ extension WritableConvertible {
/// `FileKitError.WriteToFileFail`,
/// `FileKitError.WritableConvertiblePropertyNil`
///
public func writeToPath(path: Path, atomically useAuxiliaryFile: Bool) throws {
public func writeToPath(_ path: Path, atomically useAuxiliaryFile: Bool) throws {
try writable.writeToPath(path, atomically: useAuxiliaryFile)
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/DirectoryEnumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ import Foundation

/// An enumerator for the contents of a directory that returns the paths of all
/// files and directories contained within that directory.
public struct DirectoryEnumerator: GeneratorType {
public struct DirectoryEnumerator: IteratorProtocol {

private let _path: Path, _enumerator: NSDirectoryEnumerator?
fileprivate let _path: Path, _enumerator: FileManager.DirectoryEnumerator?

/// Creates a directory enumerator for the given path.
///
/// - Parameter path: The path a directory enumerator to be created for.
public init(path: Path) {
_path = path
_enumerator = NSFileManager().enumeratorAtPath(path._safeRawValue)
_enumerator = FileManager().enumerator(atPath: path._safeRawValue)
}

/// Returns the next path in the enumeration.
Expand Down
53 changes: 18 additions & 35 deletions Sources/DispatchEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,42 @@

import Foundation

/// Dispatch source type.
public struct DispatchSourceType {

// MARK: - Static Properties

/// A dispatch source that monitors a file descriptor for events defined by `dispatch_source_vnode_flags_t`.
public static let Vnode = DISPATCH_SOURCE_TYPE_VNODE

/// A dispatch source that monitors a file descriptor for pending bytes available to be read.
public static let Read = DISPATCH_SOURCE_TYPE_READ

/// A dispatch source that monitors a file descriptor for available buffer space to write bytes.
public static let Write = DISPATCH_SOURCE_TYPE_WRITE

}


/// Vnode Events.
public struct DispatchVnodeEvents: OptionSetType, CustomStringConvertible, CustomDebugStringConvertible {
/// File System Events.
public struct DispatchFileSystemEvents: OptionSet, CustomStringConvertible, CustomDebugStringConvertible {

// MARK: - Events

/// The file-system object was deleted from the namespace.
public static let Delete = DispatchVnodeEvents(rawValue: DISPATCH_VNODE_DELETE)
public static let Delete = DispatchFileSystemEvents(rawValue: DispatchSource.FileSystemEvent.delete.rawValue)

/// The file-system object data changed.
public static let Write = DispatchVnodeEvents(rawValue: DISPATCH_VNODE_WRITE)
public static let Write = DispatchFileSystemEvents(rawValue: DispatchSource.FileSystemEvent.write.rawValue)

/// The file-system object changed in size.
public static let Extend = DispatchVnodeEvents(rawValue: DISPATCH_VNODE_EXTEND)
public static let Extend = DispatchFileSystemEvents(rawValue: DispatchSource.FileSystemEvent.extend.rawValue)

/// The file-system object metadata changed.
public static let Attribute = DispatchVnodeEvents(rawValue: DISPATCH_VNODE_ATTRIB)
public static let Attribute = DispatchFileSystemEvents(rawValue: DispatchSource.FileSystemEvent.attrib.rawValue)

/// The file-system object link count changed.
public static let Link = DispatchVnodeEvents(rawValue: DISPATCH_VNODE_LINK)
public static let Link = DispatchFileSystemEvents(rawValue: DispatchSource.FileSystemEvent.link.rawValue)

/// The file-system object was renamed in the namespace.
public static let Rename = DispatchVnodeEvents(rawValue: DISPATCH_VNODE_RENAME)
public static let Rename = DispatchFileSystemEvents(rawValue: DispatchSource.FileSystemEvent.rename.rawValue)

/// The file-system object was revoked.
public static let Revoke = DispatchVnodeEvents(rawValue: DISPATCH_VNODE_REVOKE)
public static let Revoke = DispatchFileSystemEvents(rawValue: DispatchSource.FileSystemEvent.revoke.rawValue)

/// The file-system object was created.
public static let Create = DispatchVnodeEvents(rawValue: 0x1000)
public static let Create = DispatchFileSystemEvents(rawValue: 0x1000)

/// All of the event IDs.
public static let All: DispatchVnodeEvents = [.Delete, .Write, .Extend, .Attribute, .Link, .Rename, .Revoke, .Create]
public static let All: DispatchFileSystemEvents = [.Delete, .Write, .Extend, .Attribute, .Link, .Rename, .Revoke, .Create]

// MARK: - All Events

/// An array of all of the events.
public static let allEvents: [DispatchVnodeEvents] = [
public static let allEvents: [DispatchFileSystemEvents] = [
.Delete, .Write, .Extend, .Attribute, .Link, .Rename, .Revoke, .Create
]

Expand All @@ -77,25 +60,25 @@ public struct DispatchVnodeEvents: OptionSetType, CustomStringConvertible, Custo
/// A textual representation of `self`.
public var description: String {
var result = ""
for (index, element) in DispatchVnodeEvents.allEvents.enumerate() {
for (index, element) in DispatchFileSystemEvents.allEvents.enumerated() {
if self.contains(element) {
let name = DispatchVnodeEvents.allEventNames[index]
let name = DispatchFileSystemEvents.allEventNames[index]
result += result.isEmpty ? "\(name)": ", \(name)"
}
}
return String(self.dynamicType) + "[\(result)]"
return String(describing: type(of: self)) + "[\(result)]"
}

/// A textual representation of `self`, suitable for debugging.
public var debugDescription: String {
var result = ""
for (index, element) in DispatchVnodeEvents.allEvents.enumerate() {
for (index, element) in DispatchFileSystemEvents.allEvents.enumerated() {
if self.contains(element) {
let name = DispatchVnodeEvents.allEventNames[index] + "(\(element.rawValue))"
let name = DispatchFileSystemEvents.allEventNames[index] + "(\(element.rawValue))"
result += result.isEmpty ? "\(name)": ", \(name)"
}
}
return String(self.dynamicType) + "[\(result)]"
return String(describing: type(of: self)) + "[\(result)]"
}

// MARK: - Initialization
Expand Down
Loading