Getting a Segmentation Fault: 11 with Swift 5.2 When Using Filemanager.Default.Currentdirectorypath

Getting a Segmentation fault: 11 with Swift 5.2 when using FileManager.default.currentDirectoryPath

Turns out that in this case, the problem was in rogue overlay dylibs that were in place because I've been using SwiftGen.

The solution is to either uninstall SwiftGen by calling

brew uninstall swiftgen

or following Nikolaj's answer from Swift bug tracking system by reinstalling SwiftGen with

--build-from-source

option and removing the dylibs from "lib" folder.

Segmentation fault on a simple swift script

I had a script which was working and suddenly stopped. Exactly on the line where I have created an URL. It was working on Xcode but not from terminal.

Looks like, it is bug.

If you first compile by using swiftc then run it, it is working.

I have found the answer in the following page:

https://blog.kulman.sk/workaround-for-swift-scripts-crash/

How to run terminal command in swift from any directory?

There is a deprecated property currentDirectoryPath on Process.

On the assumption you won't want to use a deprecated property, after reading its documentation head over to the FileManager and look at is provisions for managing the current directory and their implications.

Or just use cd as you've considered – you are launching a shell (zsh) with a shell command line as an argument. A command line can contain multiple commands separated by semicolons so you can prepend a cd to your command value.

The latter approach avoids changing your current process' current directory.

HTH

Command failed due to signal: Segmentation fault: 11 Xcode 8.0

I finally found the problem and solved it.

I first Created new project,
then moved my source files, one at a time to the new project,

I finally found the problem was not even related to Alamofire.

The error was coming from a library which I used for managing files

Maybe these steps will help someone

String(contentsOf: URL) returns No such file or directory

The issue is with this line:

let file = "Documents⁩/MyAppName⁩/x.csv"

You can't see it but between the s and / there is a hidden character - U+2069 - "POP DIRECTIONAL ISOLATE". Retype that line again without any special characters and your code will work.

That aside, here is how you should create the URL to the Documents folder.

let home = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

let file = "MyAppName⁩/x.csv"


Related Topics



Leave a reply



Submit