<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 29, 2015, at 1:22 PM, Jonas Fredriksson via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">second, to read a file I tried fopen from Glibc but i requires "UnsafePointer<Int8>". how do I declare that, ie var file: UnsafePointer<Int8>?</span><br style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote></div><br class=""><div class="">You probably wouldn’t declare a variable of that type. Instead just pass a String for that parameter — the compiler will convert to a C string for you.</div><div class=""><br class=""></div><div class="">For now the best documentation comes from the <i class="">Using Swift With Cocoa And Objective-C</i> book, which has a section on plain C APIs:</div><div class=""><br class=""></div><div class=""><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span><b class="">Constant Pointers</b></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>When a function is declared as taking a UnsafePointer<Type> argument, it can accept any of the following:</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>...</div><div class=""><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>* A String value, if Type is Int8 or UInt8. The string will automatically be converted to UTF8 in a buffer that lasts for the duration of the call.</div></div></div><div class=""><br class=""></div><div class="">Whether that’s appropriate for fopen() depends on whether the Linux filesystem APIs use UTF-8 encoding. (Sorry, I don’t know Linux well enough to say.) If they don’t, you’ll have trouble with filenames containing non-ASCII characters; in that case you’d need to write a function to encode the String into a byte array in the right encoding, and then pass that to fopen().</div><div class=""><br class=""></div><div class="">—Jens</div></body></html>