Posts

Post not yet marked as solved
6 Replies
995 Views
Suppose I have classes foo and bar: class foo { } class bar: foo { } I will never instantiate foo, but I will instantiate bar, and other foo subclasses. (foo will provide some functions for its subclasses to use and potentially override, so it's not something that could be replaced with a protocol, as I understand it.) Now, suppose that I wanted to define a class variable in foo, that would be available to all subclasses, and I wanted to set the value of that variable at runtime, from outside foo and any of its subclasses. How do I do this? I've been wrestling with all kinds of different syntax and can't figure it out. Or is there a better way to achieve the same goal in Swift that my brain hasn't grokked yet?
Posted Last updated
.
Post not yet marked as solved
7 Replies
887 Views
How can I copy a file or a folder in the same manner as ditto, via Swift? What I mean is that all file attributes - extended attributes, permission settings, flags, timestamps, etc - are maintained on the copy? I have tried the following: try FileManager.default.copyItem(atPath: srcPath, toPath: destPath) However, in my testing, this maintains some attributes, but the extended attributes get mangled a bit. For example, I applied a quarantine flag to a test file, and here's what it looks like on the original and new files: $ xattr -l test.txt newtest.txt test.txt: com.apple.quarantine: 0083;5991b778;Safari.app;BC4DFC58-0D26-460D-9688-81D119298642 newtest.txt: com.apple.quarantine: 0082;6051c84a;; If I copy the file using ditto instead, I get this: $ ditto test.txt newtest.txt $ xattr -l test.txt newtest.txt test.txt: com.apple.quarantine: 0083;5991b778;Safari.app;BC4DFC58-0D26-460D-9688-81D119298642 newtest.txt: com.apple.quarantine: 0083;5991b778;Safari.app;BC4DFC58-0D26-460D-9688-81D119298642 I could simply call ditto from Swift, but that's a less ideal solution.
Posted Last updated
.