We can obtain the source code of a webpage, but the form of this source code can be binary. can also be HTML, how do we achieve the conversion between the two different types? In iOS, you can use a single method for simple conversions.
Implement the Code in Viewdidiload () such as the following:
Override Func Viewdidload () { super.viewdidload () var binarystr = NSData (Contentsofurl:nsurl (string: "/HTTP// Www.baidu.com ")!) println ("binary data: \ (BINARYSTR)")//The binary data is printed here; var htmlstr = NSString (data:binarystr!, encoding: nsutf8stringencoding)//binary conversion to HTML println ("HTML data: \ (HTMLSTR)")//Output HTML }
This enables the acquisition of binary Web page data directly into HTML, very convenient.
GitHub home: https://github.com/chenyufeng1991. Welcome to visit us!
iOS project development Practice--Web source for binary and HTML conversion