swift-playground

How to add a CocoaPod framework to Xcode 8 Playground

泪湿孤枕 提交于 2019-12-30 10:12:19
问题 I tried to add some pods to the Playground within an Xcode project. Unfortunately, the only scope supported is targets since the update, and link_with is no longer supported. ERROR: [!] Invalid Podfile file: [!] The specification of link_with in the Podfile is now unsupported, please use target blocks instead. When I use target blocks, I get this error: [!] Unable to find a target named MyPlayground , did find Target_1 , Target_2 OR: [!] Unable to find a target named MyPlayground.playground ,

binary operator / cannot be applied to operands of type Int and Double [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 10:04:32
问题 This question already has answers here : Multiplying variables and doubles in swift (2 answers) So if string is not NilLiteralConvertible… what do some string functions return? (1 answer) Closed 4 years ago . Hello brand new to Swift, and programming in general. Going through an exercise the code given is exactly: //: Playground - noun: a place where people can play import UIKit let height = 12 let width = 10 let area = height * width let areaInMeters = area / 10.762 But I get the error,

How can I display views using autolayout constraints in Xcode playground?

ぃ、小莉子 提交于 2019-12-30 04:20:25
问题 I am trying to display views configured with autolayout constraints in XCode playground , but it doesn't seem to work. It's like playground ignores the constraints completely, and I can't find information about this issue anywhere. Here's the code I tried: let view = UIView() view.frame = CGRectMake(0, 0, 400, 200) view.backgroundColor = UIColor.lightGrayColor() let label = UILabel() // I can only see the label if I set a frame // UILabel(frame: CGRectMake(0, 0, 200, 50)) label

NSTimer.scheduledTimerWithTimeInterval in Swift Playground

倖福魔咒の 提交于 2019-12-29 08:38:07
问题 All the examples I've seen on using the "NSTimer.scheduledTimerWithTimeInterval" within Swift show using the "target: self" parameter, but unfortunately this doesn't work in Swift Playgrounds directly. Playground execution failed: <EXPR>:42:13: error: use of unresolved identifier 'self' target: self, Here's an example referenced above that results in the error: func printFrom1To1000() { for counter in 0...1000 { var a = counter } } var timer = NSTimer.scheduledTimerWithTimeInterval(0, target:

Sequence of elements, but “join is unavailable: call the 'joinWithSeparator()'” error

杀马特。学长 韩版系。学妹 提交于 2019-12-29 07:57:10
问题 Why do I get the error "join is unavailable: call the joinWithSeparator() " at line 16 (the last line below) when I try to run it on playground? And, how can I fix it? class Person { var firstName: String? var lastName: String? let gender = "female" func fullName() -> String { var parts: [String] = [] if let firstName = self.firstName { parts += [firstName] } if let lastName = self.lastName { parts += [lastName] } return " ".join(parts) } } 回答1: The error message tells you what the problem is

Fixing low FPS in Swift Playground

给你一囗甜甜゛ 提交于 2019-12-29 01:38:14
问题 My SpriteKit playground book averaged 15 FPS on my MacBook Pro. Do playgrounds run slower than iOS device simulations? If I run the same playground book on my iPad Pro, will the FPS limitation be similar? Will other apps opened on my computer limit the speed of playgrounds? EDIT: Moving code such as subclasses and extensions to auxiliary code in the "Sources" folder of the playground book allow the simulation to run quicker because the code only compiles once. 回答1: On the Mac, Xcode's

Type does not have a member

给你一囗甜甜゛ 提交于 2019-12-27 15:56:45
问题 I'm playing around with a Swift playground working on a new class. For some reason I keep getting an error that the class "does not have a member type" with the name of a constant defined three lines earlier. Here is the code: import Foundation class DataModel { let myCalendar = NSCalendar.autoupdatingCurrentCalendar() var myData = [NSDate : Float]() let now = NSDate() let components = myCalendar.components(.CalendarUnitYear | .CalendarUnitMonth, fromDate: now) } Xcode Beta6 keeps give me an

Smooth UIBezierPath

情到浓时终转凉″ 提交于 2019-12-25 00:14:03
问题 I created in a playground a uibezierpath added manually values and it works fine. The results is : Now my goal is to smooth the curve and remove these "sharp" corners. I'm thinking on a interpolation function but not sure. Below my actual code : //: Playground - noun: a place where people can play import Foundation import UIKit import CoreGraphics import QuartzCore class DemoView: UIView { override func draw(_ rect: CGRect) { let origin = CGPoint(x: frame.size.width / 2, y: frame.size.height

Discrepancies in time when using DispatchQueue in Swift

房东的猫 提交于 2019-12-24 21:01:09
问题 I've got a code which must be executed every half a second and I'm using the Xcode playground. I used this top answer and got a code like this: for (index, item) in array.enumerated() { DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(index), execute: { print("\(index) - \(df.string(from: Date()))" //play sound every second }) } This code is executed every second (I know that I have to divide it by 2 to get half a second but wanted to see the results). I used the DateFormatter to

How come I can't successfully load an NSImage from it's full path? Swift 2

情到浓时终转凉″ 提交于 2019-12-24 16:04:41
问题 I'm trying to load an image from an absolute path into an NSImage and even though the same full path works in other scenarios when I'm using it in this context, the variable just ends up being nil . I've tried using both the file path and an NSURL to achieve it. //: Playground - noun: a place where people can play import Cocoa import AppKit print ("Starting") /** Attempt to do via NSURL **/ // The workspace var workspace = NSWorkspace.sharedWorkspace() // Main screen var screen = NSScreen