Skip to content

Commit

Permalink
Merge pull request #14 from nori0620/update_xcode7
Browse files Browse the repository at this point in the history
Xcode7
  • Loading branch information
nori0620 committed Oct 25, 2015
2 parents f4dd2be + 1614db9 commit 50b567b
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode6.4
osx_image: xcode7

script:
- bundle exec rake default
9 changes: 8 additions & 1 deletion SwiftFilePath.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@
CC7832E31A610124005E77C3 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Norihiro Sakamoto";
TargetAttributes = {
CC7832EB1A610124005E77C3 = {
Expand Down Expand Up @@ -268,6 +270,7 @@
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -343,6 +346,7 @@
INFOPLIST_FILE = SwiftFilePath/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.nori0620.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Expand All @@ -359,6 +363,7 @@
INFOPLIST_FILE = SwiftFilePath/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.nori0620.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Expand All @@ -377,6 +382,7 @@
);
INFOPLIST_FILE = SwiftFilePathTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.nori0620.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -390,6 +396,7 @@
);
INFOPLIST_FILE = SwiftFilePathTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.nori0620.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:SwiftFilePath.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
2 changes: 1 addition & 1 deletion SwiftFilePath/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>me.nori0620.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
52 changes: 38 additions & 14 deletions SwiftFilePath/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class Path {

public class func isDir(path:NSString) -> Bool {
var isDirectory: ObjCBool = false
let isFileExists = NSFileManager.defaultManager().fileExistsAtPath(path as! String, isDirectory:&isDirectory)

NSFileManager.defaultManager().fileExistsAtPath(path as String, isDirectory:&isDirectory)
return isDirectory ? true : false
}

Expand Down Expand Up @@ -46,11 +45,11 @@ public class Path {
}

public var basename:NSString {
return path_string.lastPathComponent
return ( path_string as NSString ).lastPathComponent
}

public var parent: Path{
return Path( path_string.stringByDeletingLastPathComponent )
return Path( (path_string as NSString ).stringByDeletingLastPathComponent )
}

// MARK: - Instance methods
Expand All @@ -62,7 +61,14 @@ public class Path {
public func remove() -> Result<Path,NSError> {
assert(self.exists,"To remove file, file MUST be exists")
var error: NSError?
let result = fileManager.removeItemAtPath(path_string, error:&error)
let result: Bool
do {
try fileManager.removeItemAtPath(path_string)
result = true
} catch let error1 as NSError {
error = error1
result = false
}
return result
? Result(success: self)
: Result(failure: error!);
Expand All @@ -71,9 +77,15 @@ public class Path {
public func copyTo(toPath:Path) -> Result<Path,NSError> {
assert(self.exists,"To copy file, file MUST be exists")
var error: NSError?
let result = fileManager.copyItemAtPath(path_string,
toPath: toPath.toString(),
error: &error)
let result: Bool
do {
try fileManager.copyItemAtPath(path_string,
toPath: toPath.toString())
result = true
} catch let error1 as NSError {
error = error1
result = false
}
return result
? Result(success: self)
: Result(failure: error!)
Expand All @@ -82,9 +94,15 @@ public class Path {
public func moveTo(toPath:Path) -> Result<Path,NSError> {
assert(self.exists,"To move file, file MUST be exists")
var error: NSError?
let result = fileManager.moveItemAtPath(path_string,
toPath: toPath.toString(),
error: &error)
let result: Bool
do {
try fileManager.moveItemAtPath(path_string,
toPath: toPath.toString())
result = true
} catch let error1 as NSError {
error = error1
result = false
}
return result
? Result(success: self)
: Result(failure: error!)
Expand All @@ -93,10 +111,16 @@ public class Path {
private func loadAttributes() -> NSDictionary? {
assert(self.exists,"File must be exists to load file.< \(path_string) >")
var loadError: NSError?
let result = self.fileManager.attributesOfItemAtPath(path_string, error: &loadError)
let result: [NSObject: AnyObject]?
do {
result = try self.fileManager.attributesOfItemAtPath(path_string)
} catch let error as NSError {
loadError = error
result = nil
}

if let error = loadError {
println("Error< \(error.localizedDescription) >")
print("Error< \(error.localizedDescription) >")
}

return result
Expand All @@ -106,7 +130,7 @@ public class Path {

// MARK: -

extension Path: Printable {
extension Path: CustomStringConvertible {
public var description: String {
return "\(NSStringFromClass(self.dynamicType))<path:\(path_string)>"
}
Expand Down
41 changes: 28 additions & 13 deletions SwiftFilePath/PathExtensionDir.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension Path {
}

private class func userDomainOf(pathEnum:NSSearchPathDirectory)->Path{
let pathString = NSSearchPathForDirectoriesInDomains(pathEnum, .UserDomainMask, true)[0] as! String
let pathString = NSSearchPathForDirectoriesInDomains(pathEnum, .UserDomainMask, true)[0]
return Path( pathString )
}

Expand All @@ -47,10 +47,16 @@ extension Path: SequenceType {
assert(self.isDir,"To get children, path must be dir< \(path_string) >")
assert(self.exists,"Dir must be exists to get children.< \(path_string) >")
var loadError: NSError?
let contents = self.fileManager.contentsOfDirectoryAtPath(path_string
, error: &loadError)
let contents: [AnyObject]?
do {
contents = try self.fileManager.contentsOfDirectoryAtPath(path_string
)
} catch let error as NSError {
loadError = error
contents = nil
}
if let error = loadError {
println("Error< \(error.localizedDescription) >")
print("Error< \(error.localizedDescription) >")
}

return contents!.map({ [unowned self] content in
Expand All @@ -64,7 +70,11 @@ extension Path: SequenceType {
}

public func content(path_string:NSString) -> Path {
return Path( self.path_string.stringByAppendingPathComponent(path_string as! String) )
return Path(
NSURL(fileURLWithPath: self.path_string)
.URLByAppendingPathComponent( path_string as String )
.path!
)
}

public func child(path:NSString) -> Path {
Expand All @@ -73,23 +83,28 @@ extension Path: SequenceType {

public func mkdir() -> Result<Path,NSError> {
var error: NSError?
let result = fileManager.createDirectoryAtPath(path_string,
withIntermediateDirectories:true,
attributes:nil,
error: &error
)
let result: Bool
do {
try fileManager.createDirectoryAtPath(path_string,
withIntermediateDirectories:true,
attributes:nil)
result = true
} catch let error1 as NSError {
error = error1
result = false
}
return result
? Result(success: self)
: Result(failure: error!)

}

public func generate() -> GeneratorOf<Path> {
public func generate() -> AnyGenerator<Path> {
assert(self.isDir,"To get iterator, path must be dir< \(path_string) >")
let iterator = fileManager.enumeratorAtPath(path_string)
return GeneratorOf<Path>() {
return anyGenerator() {
let optionalContent = iterator?.nextObject() as! String?
if var content = optionalContent {
if let content = optionalContent {
return self.content(content)
} else {
return .None
Expand Down
53 changes: 38 additions & 15 deletions SwiftFilePath/PathExtensionFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
extension Path {

public var ext:NSString {
return path_string.pathExtension
return NSURL(fileURLWithPath:path_string).pathExtension!
}

public func touch() -> Result<Path,NSError> {
Expand All @@ -22,11 +22,16 @@ extension Path {

public func updateModificationDate(date: NSDate = NSDate() ) -> Result<Path,NSError>{
var error: NSError?
let result = fileManager.setAttributes(
[NSFileModificationDate :date],
ofItemAtPath:path_string,
error:&error
)
let result: Bool
do {
try fileManager.setAttributes(
[NSFileModificationDate :date],
ofItemAtPath:path_string)
result = true
} catch let error1 as NSError {
error = error1
result = false
}
return result
? Result(success: self)
: Result(failure: error!)
Expand All @@ -41,12 +46,17 @@ extension Path {
public func readString() -> String? {
assert(!self.isDir,"Can NOT read data from dir")
var readError:NSError?
let read = String(contentsOfFile: path_string,
encoding: NSUTF8StringEncoding,
error: &readError)
let read: String?
do {
read = try String(contentsOfFile: path_string,
encoding: NSUTF8StringEncoding)
} catch let error as NSError {
readError = error
read = nil
}

if let error = readError {
println("readError< \(error.localizedDescription) >")
print("readError< \(error.localizedDescription) >")
}

return read
Expand All @@ -55,10 +65,16 @@ extension Path {
public func writeString(string:String) -> Result<Path,NSError> {
assert(!self.isDir,"Can NOT write data from dir")
var error: NSError?
let result = string.writeToFile(path_string,
atomically:true,
encoding: NSUTF8StringEncoding,
error: &error)
let result: Bool
do {
try string.writeToFile(path_string,
atomically:true,
encoding: NSUTF8StringEncoding)
result = true
} catch let error1 as NSError {
error = error1
result = false
}
return result
? Result(success: self)
: Result(failure: error!)
Expand All @@ -74,7 +90,14 @@ extension Path {
public func writeData(data:NSData) -> Result<Path,NSError> {
assert(!self.isDir,"Can NOT write data from dir")
var error: NSError?
let result = data.writeToFile(path_string, options:.DataWritingAtomic, error: &error)
let result: Bool
do {
try data.writeToFile(path_string, options:.DataWritingAtomic)
result = true
} catch let error1 as NSError {
error = error1
result = false
}
return result
? Result(success: self)
: Result(failure: error!)
Expand Down

0 comments on commit 50b567b

Please sign in to comment.