在Swift游乐场中使用MapKit显示地图以便快速查看?

很高兴看到swift-playground的标签 – 喜欢看到这种情况继续下去。

我一直在修补Swift,我想知道MapKit是否可以在操场上使用,这样你就可以使用Quick Look功能,这样我就可以迭代并使用我的工作预览。我还没想出语法,所以我想问一下是否有人在游乐场环境中探讨过这个问题。我想我需要一些代码来建立它作为一个视图控制器。

import UIKit
import MapKit

// Sample UIView code which works great in the playground.
//var myView:UIView = UIView();
//myView.frame = CGRectMake(0,320,560)
//myView.backgroundColor = UIColor.blueColor()

// Non working map code - no errors but can't figure out what to call or initiate to get the view in the Quick Look side.

var mapView = MKMapView();
mapView.region.center.latitude = mapView.userLocation.coordinate.latitude;
mapView.region.center.longitude = mapView.userLocation.coordinate.longitude;
mapView.region.span.latitudeDelta = 0.00725;
mapView.region.span.longitudeDelta = 0.00725;

猜测我只是缺少一些简单的mapView来初始化自己等等。我喜欢解释的游乐场区域进行修补,只需要弄清楚它是否可以执行mao功能,而不是仅仅在Xcode中编写.swift文件和环境并获取更正式。

对于OS X上的XCode7.1和Swift2.1,我打开了时间轴并执行了以下操作:
import MapKit
import XCPlayground

let delta = 5.0
let frame = CGRect( x:0,y:0,width:200,height:200 )
let mapView = MKMapView( frame: frame )
var region = MKCoordinateRegion()
region.center.latitude = 31.0
region.center.longitude = -110.0
region.span.latitudeDelta = delta
region.span.longitudeDelta = delta
mapView.setRegion( region,animated: true )

XCPlaygroundPage.currentPage.liveView = mapView
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

Xcode 9.x,Swift 4.1更新:

导入PlaygroundSupport
导入MapKit

let delta = 5.0
let frame = CGRect( x:0,animated: true )

PlaygroundPage.current.liveView = mapView
PlaygroundPage.current.needsIndefiniteExecution = true

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...