简体   繁体   中英

Text gets truncated when converted from NSString to Swift String

I have this little code to download the HTML source of a webpage.

var buffer = NSString(contentsOfURL: path, encoding: NSUTF8StringEncoding, error: nil)
// buffer = buffer?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
let html:String = buffer ?? ""

While buffer does always contain the full sourcecode of the page the variable html is always only a truncated piece of it. No matter what webpage I use as path. I used the po (print object) function of the Xcode debugger to check this.

As you can see I already tried to remove whitespaces but it did not help. Why is the happening and how can I prevent this?

EDIT:

I know I can also use the following method but the the string is truncated too.

var buffer = String(contentsOfURL: path, encoding: NSUTF8StringEncoding, error: nil)

try using println(html) in the code. The 'po' command is truncating the string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM