标签: swift-playground

如何在XCode 8 Playgrounds中使用Swift 2.3?

我的操场项目是用Swift 2.2编写的,我希望利用时间轴视觉效果并尝试在Xcode 8 beta中引入新的调试功能.默认情况下,Xcode 8 beta在Playgrounds中使用Swift 3,我无法找到改变它的方法.遗憾的是,将我的代码更新为Swift 3不是一个选项,因为我的代码将在Swift 2.2环境的服务器上编译.

swift swift-playground xcode8

33
推荐指数
1
解决办法
8309
查看次数

在Swift Playground中没有这样的模块'Cocoa'

我正在尝试遵循WWDC playgrounds会话中使用的一些代码,我正在尝试导入Cocoa框架:

import Cocoa
Run Code Online (Sandbox Code Playgroud)

但是我在助理编辑器中收到以下错误

Playground execution failed: error: <REPL>:3:8: error: no such module 'Cocoa'
Run Code Online (Sandbox Code Playgroud)

我在视频中的时间是41:20,如果这有帮助的话.

swift swift-playground

32
推荐指数
2
解决办法
3万
查看次数

Xcode 6 - 防止快速游乐场刷新

有时我在操场上写一些代码需要一段时间才能完成.例如:

var values = [[Int]](count: 10000, repeatedValue: [Int](count: 73, repeatedValue: 0))
Run Code Online (Sandbox Code Playgroud)

每当游乐场想要刷新结果时,它必须运行那段代码(需要一段时间才能运行)并且它使整个Xcode非常缓慢.

我仍然想在操场上编写我的代码,因为它有一些非常好的功能来测试你的算法.但是,我发现我必须对某些代码行进行注释才能继续编写而不会中断.

有没有办法对Xcode说:"现在不要跑我的操场.我会告诉你什么时候准备好了."?

xcode swift xcode6 swift-playground

28
推荐指数
2
解决办法
7040
查看次数

在Swift 2.0中将Character转换为Int

我只想将一个角色转换成一个Int.

这应该很简单.但我没有发现以前的答案有用.总有一些错误.也许是因为我在Swift 2.0中尝试它.

for i in (unsolved.characters) {
  fileLines += String(i).toInt()
  print(i)
}
Run Code Online (Sandbox Code Playgroud)

int character swift swift-playground swift2

28
推荐指数
2
解决办法
3万
查看次数

在Swift中使用未声明的类型'UIImage'

在swift中使用此函数,我收到编译器错误.功能是:

class func imageWithImage (imageToResize : UIImage, scaledToSize newSize : CGSize) {
    return imageToResize;
}
Run Code Online (Sandbox Code Playgroud)

而错误是:

  1. 使用未声明类型'UIImage'
  2. 使用未声明类型'CGSize'

这有什么问题..?我怎么能在Swift中使用UIImage ..?

uiimage cgfloat ios swift swift-playground

27
推荐指数
1
解决办法
2万
查看次数

使我的函数计算数组Swift的平均值

我希望我的函数计算我的Double类型数组的平均值.该数组称为"投票".现在,我有10个号码.

当我调用average function以获得阵列投票的平均值时,它不起作用.

这是我的代码:

var votes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

func average(nums: Double...) -> Double {
    var total = 0.0
    for vote in votes {
        total += vote
    }
    let votesTotal = Double(votes.count)
    var average = total/votesTotal
    return average
}

average[votes]
Run Code Online (Sandbox Code Playgroud)

我如何在此处调用平均值来获得平均值?

arrays function swift swift-playground

26
推荐指数
2
解决办法
2万
查看次数

无法在Swift Playgrounds上捕获视频数据,captureOutput AVCaptureVideoDataOutputSampleBufferDelegate委托方法未调用

我想在Swift Playgrounds iPad应用程序上访问iPad的相机.我发现捕捉视频数据是不可能的,即使我的游乐场运行正常.

captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!),AVCaptureVideoDataOutputSampleBufferDelegate协议的委托方法,没有被调用(可能是因为没有视频数据进入),而它在我的iOS应用程序中.

我的操场上的视图应该显示FaceTime摄像机视图.为什么我不能显示相机输出,即使Apple明确表示允许这样做?此外,Playground应用程序在我打开操场时会立即询问相机权限,因此应该以某种方式允许它.

import UIKit
import CoreImage
import AVFoundation
import ImageIO
import PlaygroundSupport

class Visage: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {

    var visageCameraView : UIView = UIView()
    fileprivate var faceDetector : CIDetector?
    fileprivate var videoDataOutput : AVCaptureVideoDataOutput?
    fileprivate var videoDataOutputQueue : DispatchQueue?
    fileprivate var cameraPreviewLayer : AVCaptureVideoPreviewLayer?
    fileprivate var captureSession : AVCaptureSession = AVCaptureSession()
    fileprivate let notificationCenter : NotificationCenter = NotificationCenter.default

    override init() {
        super.init()

        self.captureSetup(AVCaptureDevicePosition.front)
        var faceDetectorOptions …
Run Code Online (Sandbox Code Playgroud)

camera swift swift-playground

26
推荐指数
1
解决办法
1167
查看次数

在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, 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;
Run Code Online (Sandbox Code Playgroud)

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

mapkit swift swift-playground

24
推荐指数
2
解决办法
8991
查看次数

Xcode 7 Playground错误:无效的上下文0x0

我在调试区域出现此错误,即使我的playground文件为空:

9月23日11:03:50 MyPlayground [68315]:CGContextSaveGState:无效的上下文0x0.如果要查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境变量.

9月23日11:03:50 MyPlayground [68315]:CGContextTranslateCTM:无效的上下文0x0.如果要查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境变量.

9月23日11:03:50 MyPlayground [68315]:CGContextRestoreGState:无效的上下文0x0.如果要查看回溯,请设置CG_CONTEXT_SHOW_BACKTRACE环境变量.

我看到了修改plist文件的答案.但是,我使用的是.playground文件,而不是普通的iOS项目..playground中没有plist文件.任何解决方案?

我在用Xcode Version 7.0 (7A220).

xcode cgcontext ios swift swift-playground

22
推荐指数
1
解决办法
1881
查看次数

iOS/tvOS游乐场失败,"无法找到所选运行目标的执行服务"

迁移到XCode 7.1后,我不能在iOS和tvOS平台上使用playground.只有OS X有效.最简单的操场代码会产生错误消息:

无法找到所选运行目标的执行服务

我怀疑它与XCode没有找到合适的模拟器,但我不知道在哪里以及如何配置它.

我在现有项目中尝试了游乐场,以及刚刚在启动画面中新创建的游乐场.

什么想法可能是错的?

更新:

检查控制台提供了更多的洞察力,但仍不清楚如何修复:

24/10/2015 10:16:10,193 lsd[279]: LaunchServices: Could not store lsd-identifiers file at /private/var/db/lsd/com.apple.lsdschemes.plist
24/10/2015 10:16:10,212 com.apple.usbmuxd[82]: LOCKDOWN_V2_BONJOUR_SERVICE_NAME is _apple-mobdev2._tcp,8de107c0
24/10/2015 10:16:10,248 Xcode[819]:  DeveloperPortal: Using pre-existing current store at URL (file:///Users/courteouselk/Library/Developer/Xcode/DeveloperPortal%207.1.db).
24/10/2015 10:16:10,381 com.apple.CoreSimulator.CoreSimulatorService[461]: Requested phone is is not available for pairing.  Assuming it has the capability.
24/10/2015 10:16:10,384 com.apple.CoreSimulator.CoreSimulatorService[461]: Requested phone is is not available for pairing.  Assuming it has the capability.
24/10/2015 10:16:12,929 com.apple.usbmuxd[82]: _SendAttachNotification Device 80:ea:96:04:a5:da@fe80::82ea:96ff:fe04:a5da._apple-mobdev2._tcp.local. has already appeared on interface …
Run Code Online (Sandbox Code Playgroud)

xcode swift swift-playground

22
推荐指数
3
解决办法
7025
查看次数