iOS project development Real---ios Network programming to obtain Web page HTML source code

Source: Internet
Author: User
<span id="Label3"></p><p><p>Now we are in the age of the Internet. No matter what a software or app, it will be more or less related to the network, and data interaction is constantly occurring. An application that does not involve network programming will appear low, and here we will start using Swift to develop iOS apps, and primarily for network operational functions.</p></p><p><p></p></p><p><p>The need here is to get the HTML source of a webpage, that is, to get data from the Internet. Detailed implementations such as the Following:</p></p><p><p>(1) Create an iOS project, language select swift. Then implement the following code in viewcontroller.swift, for Example:</p></p><p><p></p></p><pre name="code" class="plain"><pre name="code" class="plain"> Override func viewdidload () { super.viewdidload () var str = nsstring (contentsofurl:nsurl (string: "/http// www.baidu.com "), encoding:nsutf8stringencoding, error:nil) println (str!) The above returned is the optional type optional value, The return value may be Empty. When I make sure there is a return value, use an exclamation point!<p></p><p>Gets the Value. }</p></pre></pre><br>(2) Execution Procedure. Print the results in the Console: (baidu home HTML content too much, I just copied out a part)<p><p></p></p><p><p></p></p><pre name="code" class="html">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.