Created
January 16, 2017 08:13
-
-
Save keitaito/cf1850835b7be57eb81f1447323d2ad7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add Foundation import to be able to use NSDate class below. | |
import Foundation | |
print("Hello, world!") | |
// There is always one argument passed, which is the name of the program, | |
// that is the file name. | |
if CommandLine.argc < 2 { | |
print("No arguments are passed.") | |
let firstArgument = CommandLine.arguments[0] | |
print(firstArgument) | |
} else { | |
print("Arguments are passed.") | |
let arguments = CommandLine.arguments | |
for argument in arguments { | |
print(argument) | |
} | |
} | |
let today = NSDate() | |
print(today) | |
// Instantiate FileManager class. | |
let fileManager = FileManager.default | |
// Get home directory's URL. | |
if #available(macOS 10.12, *) { | |
let homeDirURL = fileManager.homeDirectoryForCurrentUser | |
do { | |
// Get contents of the home directory. | |
let contents = try fileManager.contentsOfDirectory(atPath: homeDirURL.path) | |
// Print them out. | |
for content in contents { | |
print(content) | |
} | |
} catch { | |
print(error) | |
} | |
} else { | |
print("The current environment is not macOS 10.12 or newer.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment