<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I’m currently using swift to build a project, and have found a pretty hard to bypass roadBlock.</div><div class=""><br class=""></div><div class="">The main workflow of the project is</div><div class="">- Read a csv file</div><div class="">- Extract the values of the rows and columns</div><div class="">- Process data extracted from file</div><div class="">- Write some results to another file</div><div class=""><br class=""></div><div class="">Pretty simple and straightforward. Got it working on OSX with 2016-05-09 (a) toolchain without problems, using the CSV parser from&nbsp;<a href="https://github.com/Daniel1of1/CSwiftV" class="">https://github.com/Daniel1of1/CSwiftV</a> with the minimal modifications to compile with swift 3.</div><div class=""><br class=""></div><div class="">But i need it to compile and work with linux ubuntu.</div><div class="">I prepared a work environment with the instructions in&nbsp;<a href="https://www.raywenderlich.com/122189/introduction-to-open-source-swift-on-linux" class="">https://www.raywenderlich.com/122189/introduction-to-open-source-swift-on-linux</a></div><div class="">and it works and compiles swift code wonderfully, even installed the same snapshot of the swift toolchain to make it all happy.</div><div class=""><br class=""></div><div class="">The problem i found is some of the string functionality i need for the csv parser to work, is not working ok in linux.</div><div class="">- String.replacingOccurences(of: stringToFind, with: stringToPutInstead)</div><div class="">does not work the same in both environments.</div><div class=""><br class=""></div><div class="">i have a csv file obtainable from&nbsp;<a href="https://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients" class="">https://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients</a></div><div class="">That contains the pattern “\r\n” and i need it to be replaced with “\n” to later on process the rest of the file.</div><div class=""><br class=""></div><div class="">the code i use is:</div><div class=""><br class=""></div><span class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;#if&nbsp;os(Linux)<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;print("Let's change those carriage returns...")<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;processedString = string.replacingOccurrences(of:&nbsp;"\r\n", with:&nbsp;"\n")<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;#else<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;processedString = string.replacingOccurrences(of:&nbsp;"\r\n", with:&nbsp;"\n")<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;#endif<br class=""></span><div class=""><span class="">And it compiles flawlessly in linux, but when it’s time to execute, it throws an error message like:<br class=""></span><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Let's change those carriage returns...</span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Illegal instruction (core dumped)</span></div></div><div class="">I tried escaping the pattern ( “\\r\\n”) and it does not throw the error, but neither replaces the code</div><div class="">When i tried executing the same code in the Linux virtual machine in the REPL environment, the sequence of events was:</div><div class=""><br class=""></div><div class="">&nbsp;1&gt;&nbsp;import Foundation<br class="">&nbsp;&nbsp;2&gt;&nbsp;let path = "/vagrant/credit_card.csv"&nbsp;<br class="">path: String = "/vagrant/credit_card.csv"<br class="">&nbsp;&nbsp;3&gt;&nbsp;let text = NSString(contentsOfFile: path as String, encoding: NSUTF8StringEncoding)&nbsp;<br class="">text: Foundation.NSString = {<br class="">&nbsp;&nbsp;Foundation.NSObject = {}<br class="">&nbsp;&nbsp;_cfinfo = {<br class="">&nbsp; &nbsp;&nbsp;info = 1920<br class="">&nbsp; &nbsp;&nbsp;pad = 0<br class="">&nbsp;&nbsp;}<br class="">&nbsp;&nbsp;_storage =&nbsp;"ID,LIMIT_BAL,SEX,EDUCATION,MARRIAGE,AGE,PAY_0,PAY_2,PAY_3,PAY_4,PAY_5,PAY_6,BILL_AMT1,BILL_AMT2,BILL_AMT3,BILL_AMT4,BILL_AMT5,BILL_AMT6,PAY_AMT1,PAY_AMT2,PAY_AMT3,PAY_AMT4,PAY_AMT5,PAY_AMT6,default payment next&nbsp;month\r\n1,20000,2,2,1,24,2,2,-1,-1,-2,-2,3913,3102,689,0,0,0,0,689,0,0,0,0,1\r\n2,120000,2,2,2,26,-1,2,0,0,0,2,2682,1725,2682,3272,3455,3261,0,1000,1000,1000,0,2000,1\r\n3,90000,2,2,2,34,0,0,0,0,0,0,29239,14027,13559,14331,14948,15549,1518,1500,1000,1000,1000,5000,0\r\n4,50000,2,2,1,37,0,0,0,0,0,0,46990,48233,49291,28314,28959,29547,2000,2019,1200,1100,1069,1000,0\r\n5,50000,1,2,1,57,-1,0,-1,0,0,0,8617,5670,35835,20940,19146,19131,2000,36681,10000,9000,689,679,0\r\n6,50000,1,1,2,37,0,0,0,0,0,0,64400,57069,57608,19394,19619,20024,2500,1815,657,1000,1000,800,0\r\n7,500000,1,1,2,29,0,0,0,0,0,0,367965,412023,445007,542653,483003,473944,55000,40000,38000,20239,13750,13770,0\r\n8,100000,2,2,2,23,0,-1,-1,0,0,-1,11876,380,601,221,-159,567,380,601,0,581,1687,1542,0\r\n9,140000,2,3,1,28,0,0,2,0,0,0,11285,14096,12108,12211,11793,"...<br class="">}<br class="">&nbsp;&nbsp;4&gt;&nbsp;var tmp = text.replacingOccurrences(of: "\r\n", with: "\n")<br class="">tmp: String = {<br class="">&nbsp;&nbsp;_core = {<br class="">&nbsp; &nbsp;&nbsp;_baseAddress = &lt;extracting data from value failed&gt;<br class=""><br class="">&nbsp; &nbsp;&nbsp;_countAndFlags = &lt;extracting data from value failed&gt;<br class=""><br class="">&nbsp; &nbsp;&nbsp;_owner = &lt;extracting data from value failed&gt;<br class=""><br class="">&nbsp;&nbsp;}<br class="">}<br class="">Execution interrupted.&nbsp;Enter code to recover and continue.<br class="">Enter LLDB commands to investigate (type :help for assistance.)</div><div class=""><br class=""></div><div class="">And i found myself without more options to know what’s happening.</div><div class=""><br class=""></div><div class="">Is it a bug i need to report? is there something i’m missing?</div><div class=""><br class=""></div><div class="">What would really be a blessing, is something akin to the xcode swift documentation that covered the linux equivalence of commands.</div><div class=""><br class=""></div><div class="">I know is a young project yet, but it really needs to improve the docs for Linux development to be viable. ( and a GUI like Xcode too ;) )</div><div class=""><br class=""></div><div class="">If anyone knows anything that can help, i’d be gratefull.</div><div class=""><br class=""></div><div class="">Carlos Barrera</div><div class=""><a href="mailto:shadowcharly@gmail.com" class="">shadowcharly@gmail.com</a></div><div class=""><br class=""></div><div class="">&nbsp;</div></div></body></html>