草庐IT

playGround

全部标签

ios - iPhone 上的 Swift playground

我目前正在学习Swift,我希望用CMMotionManager测试一些想法。具体来说,我想绘制磁力计的输出图形。Playgrounds可以做到这一点吗?即,我能否编写将在实际连接的iPhone或iPad(而非模拟器)上运行的代码,但在我正在开发的Mac上看到显示的图形和结果? 最佳答案 似乎简单的答案是“不”。引用Swift Playgrounds–WWDC 2014 Session 408的文字记录:SoanythingwhichrequiresadevicewillnotbesupportedwithPlaygrounds.不

swift - 为什么 NSBezierPath 的这个简单子(monad)类会使我的 OSX Playground 崩溃?

我正在尝试通过子类化将存储的属性添加到NSBezierPath。但是,以下代码会使Playground崩溃:importCocoaclassMyNSBezierPath:NSBezierPath{privatevarsomeProperty:Booloverrideinit(){someProperty=falsesuper.init()}requiredinit?(coderaDecoder:NSCoder){self.someProperty=falsesuper.init(coder:aDecoder)}}//thefollowinglinecausesthePlayground

swift - 如何在 Swift Playgrounds 中使用带有纹理的 SKNode 设置 SKScene?

我尝试将模板代码从SpriteKit项目复制到playground中,但当我呈现场景时,我得到的只是一个灰色屏幕。我需要创建一个SKScene吗?如果需要,我该如何将它分配给我正在使用的场景类。以下是我创建和呈现场景的代码:@objcfuncgoToGameScene(){print("GameViewLoaded")sceneView=SKView(frame:CGRect(x:0,y:0,width:666,height:500))sceneView.backgroundColor=UIColor.blackPlaygroundPage.current.liveView=scene

swift - 无法在 Swift playground 中向 SKScene 添加滑动识别器?

好吧,我对swiftplayground的工作原理还是有点陌生​​,但我正在尝试将Swift3中的滑动手势识别器添加到我的swiftplayground。按照这个http://www.spritekitlessons.com/gesture-recognizer-with-sprite-kit-and-swift/我现在有:funcswipedRight(sender:UISwipeGestureRecognizer){print("swipedright")}funcswipedLeft(sender:UISwipeGestureRecognizer){print("swipedle

swift - 在 Xcode Playgrounds 中实现 TouchBar 功能

如何在仅使用XcodePlaygrounds的情况下实现NSTouchBar?我意识到NSTouchBar及其附带的方法包括makeTouchBar()包含在NSResponder类中,它是NSView的父类(superclass)、NSViewController、NSWindow和SKView(NSView的子类。)正是出于这个原因,我有点不确定如何访问TouchBar。NSResponder的子类太多了,我不确定哪一个是正确的。据我所知,我什至无法访问所有这些,包括Playground的NSWindow,我怀疑它可能是我需要访问的。我当前的设置是:letcontainerView

core-data - 可以在 Swift Playground 中使用 Core Data 吗?

我刚开始使用Swift,想知道Playgrounds是否可以访问CoreData。如果是这样,在将数据库放入iOS项目之前预先填充数据库会非常方便。 最佳答案 在iOSPlayground中,您可以成功导入CoreData,然后调用CoreData接口(interface)中定义的函数。 关于core-data-可以在SwiftPlayground中使用CoreData吗?,我们在StackOverflow上找到一个类似的问题: https://stackov

swift - RemoveAtIndex 崩溃 Playground

我正在尝试使用String的removeAtIndex函数从字符串中删除Character。但它会使Playground崩溃。完整代码如下:letstring="SomeString"letstart=advance(string.startIndex,2)letx=string.removeAtIndex(start) 最佳答案 您已使用let声明了string,这使其不可变。由于您只能在mutableString上调用removeAtIndex,因此您可以通过使用声明string来解决此问题var代替:varstring="So

objective-c - 在应用程序中嵌入 Xcode Playground

我想制作一个CocoaOSX应用程序,用户可以在我的应用程序的一个窗口中输入和执行Swift语言代码。我的第一个想法是自己做一个基本的IDE,用系统调用来进行编译和执行;但是,我真的很想拥有交互式Playground功能。我做了研究,发现我可以创建带有嵌入式文档的XcodePlayground文件,但这引发了一个问题:Doesthedocumentationhavetobeplacedaboveandbelowtheplayground,orcanIembedaPlaygroundwithinacontainerinmyHTMLcode?我所说的XcodePlayground嵌入式文档

swift - 是否可以在 Playground 上模拟设备方向?

鉴于这种情况:XCPlaygroundPage.currentPage.liveView=TableViewController()是否可以模拟设备的方向? 最佳答案 基于在here中找到的一些逻辑KIFtestingframework,我想这应该是可能的。链接背后的Objective-C代码如下所示:-(void)simulateDeviceRotationToOrientation:(UIDeviceOrientation)orientation{[[UIDevicecurrentDevice]setValue:[NSNumbe

快速 Playground 错误 BAD_INSTRUCTION

所以我有下面的贪心算法,它给了我以下错误:Playgroundexecutionaborted:error:Executionwasinterrupted,reason:EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0).Theprocesshasbeenleftatthepointwhereitwasinterrupted,use"threadreturn-x"toreturntothestatebeforeexpressionevaluation.类://Thisclassrepresentsanundirectedgraphu