目錄:[Swift]Xcode實際操做html
本文將演示如何使用應用程序單例對象,打開指定的網頁。web
在項目導航區,打開視圖控制器的代碼文件【ViewController.swift】swift
1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib. 8 9 //建立一個字符串存儲一個網絡地址 10 let website = "https://www.cnblogs.com/strengthen/" 11 //將字符串轉換爲網址對象 12 let url = URL(string:website) 13 //獲取應用程序單例對象, 14 //使用它打開網頁的功能, 15 //打開指定網址的網頁。 16 UIApplication.shared.openURL(url!) 17 } 18 19 override func didReceiveMemoryWarning() { 20 super.didReceiveMemoryWarning() 21 // Dispose of any resources that can be recreated. 22 } 23 }