在昨天談完第8天Swift Type及Function後,今天來談談如何在Xcode寫程式時使用一些Apple內建
的iOS SDK , 設定各自的屬性和呼叫方法
可以參考以下常用的SDK關鍵技術:
地圖: MapKit,MKMapView,MKCoordinateRegion
播音樂: AVFoundation,URL,AVPlayer
播影片: AVKit,AVPlayerViewController
網頁: SafariServices,SFSafariViewController
時間: Foundation,Date,DateFormatter,Calendar,DateComponents,Void
App 講話: AVFoundation,AVSpeechSynthesizer,AVSpeechUtterance,AVSpeechSynthesisVoice
playground: PlaygroundSupport,PlaygroundPage,liveView,type property
我們先把以下程式碼複製到Play Ground , 來測試一下MapKit
import MapKit
let mapView = MKMapView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
mapView.region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.334722, longitude:-122.008889 ), latitudinalMeters: 1000,longitudinalMeters: 1000)
另外我們可以用AVPlayer來播音樂,程式碼如下
import AVFoundation
let url = URL(string: "http://www.sing2music.com/previewurl/httpsaudio-ssl-itunes-apple-comapple-assets-us-std-000001audiopreview128v456c99456c9946d-bec7-50a9-d722-1161de2a7604mzaf_5475917944631821718-plus-aac-p-m4a/")
let player = AVPlayer(url: url!)
player.play()
URL代表某個資源的位置(location of a resource)