I am reluctant to admit that I only came to know that Swift provides a builtin documentation markup syntax just a few months ago.
/** Test func
Some description here.
- Parameters:
- b:Test
- d: Test
- f: Test
- Returns: Bool
*/
func myMethod(a b:Int, c d:Int, e f:Int) -> Bool { b > d }
It seems the markup is pretty simple and has only a few keywords. But, I want to read through the complete reference. Any useful pointers?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have a need to optimize reading strategy, based on if the file is on hard disk or SSD. Does macOS provide any low-level API so that I can query such information?
My code is crashing Xcode (or even macOS kernel) during debugging - Xcode just vanishes from screen!
// pseudo code
public func hunt(in directory: URL) {
let fileIterator = fileMan.enumerator(at: directory)
// collect app packages into a list
var packages = [URL]()
for case let fileURL as URL in fileIterator {
if fileURL.pathExtension == "app" { packages.append(fileURL) }
}
// FileWrappers
var wrappers = [FileWrappers]()
for packageURL in packages {
//!!! The line below eventually crashes Xcode (or even macOS kernel once)!
wrappers[packageURL] = try? FileWrapper(url: packageURL, options: .immediate)
// NOTE: I need FileWrapper.matchesContents later in some code
}
}
// unit test case
func test() {}
myObj.hunt(in: URL(fileURLWithPath: "/Applications"))
}
I suspect that the FileWrapper constructor is traversing directories and encounter cyclic symbolic links and eventually it crashes; since it's running at system runtime level, most probably it also crashes macOS kernel!
So my question is that is there any way to detect cyclic symbolic links so that I can design my own logics similar to FileWrapper?
I have the following pseudo code:
func load(at packageURL: URL) {
let realPackageURL = packageURL.resolvingSymlinksInPath()
guard let it = fileMan.enumerator(at: realPackageURL)
for case let fileURL as URL in it {
print(fileURL)
// Get filename relative to package root directory
let relativeFileName = String(filePath.suffix(filePath.count - packagePath.count))
}
}
When called with "file:///tmp/some.app", the enumerated fileURL is actually
file:///private/tmp/GIMP.app/Contents/
packageURL.resolvingSymlinksInPath() actually does nothing, I assume /tmp is a hard link.
This makes it impossible to get a correct relative path. Is there any remedy for this?
Suppose I have the following function:
func doWork(_ someValue: Int, completionHandler: () -> Void) {
let q = DispatchQueue()
q.async {
// Long time of work
completionHandler()
}
}
How do I turn it into async function so that I can call it using await doWork()? Are there guidelines/principles/practices for this purpose?
Is there any way to get an unnamed property of a tuple given its position?
Like below:
let record = ("field1", "field2")
func getRecordFieldValue(at: Int, of record: (String, String)) -> Any? {
// pseudo code
record.[at]
}
Does Swift has the syntax that lets me get the default value of a template type T, like below:
struct VarLock<T> {
private var v = default(T) // or T()
}
I used to run VirtualBox on macOS to run Windows guests for some reasons.
Recently I bought a new Mac mini M1, now I have a problem - VB does not have a stable release for arm (yet).
What other options do I have?
BTW, I came across this doc article (https://developer.apple.com/documentation/virtualization/running_macos_in_a_virtual_machine_on_apple_silicon). I read thru it, but could not conclude if it offers the same functionalities as a full-blown VM suite; and more specifically I want to run Windows guests.
I had a customer feedback about a "zero length data" error which was captured using an exception handler and displayed using NSAlert.
My app employs [NSURLSession dataTaskWithURL:] to download XML and image data.
But I got no idea what it is about. I assume it's related to NSData, but this error never happened before (for years).
Does anyone have any idea about the source of this error?
I want to check if a given string matches a file pattern.
Does Swift have builtin support for filename globbing? Or is there any 3rd party packages for this?
I remember long time ago I could click on a button in Xcode to launch a Web page to manage iCloud data. But now I cannot find the button.
I just want some experts on Swift to confirm that the following syntaxes are equivalent:
if a > b, c > d {
}
if a > b && c > d {
}
I consulted "The Swift Programming Lanugage (version 5.7)" but the book does not cover this issue. But I believe it's true because my tests show they are the same.
I use ProcessInfo.processInfo.environment["key"] to get test parameters, but all of a sudden I could not find the UI like below:
In the screenshot above, the 2 environment variables were actually what I entered for the unit test target. I don't have any idea why they were moved there!
Any similar problems?
According to the doc:
The value returned is the same as the value returned in the kEventParamKeyCode when using Carbon Events.
So where can I find kEventParamKeyCode?
I am no expert at coordinate systems. I am kind of aware I can use its enclosingScrollView but don't know the details.
Any suggestions would be appreciated.