swift-playground

How to reference Swift Playground itself?

故事扮演 提交于 2019-11-28 08:36:04
from How to create a button programmatically? self doesn't work in swift playground : button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside) error : Playground execution failed: error: :42:13: error: use of unresolved identifier 'self' I also tried to create a class with buttonAction method inside it compiles but when I click on the button nothing prints in console import UIKit class myself { func buttonAction(sender:UIButton!) { println("Button tapped") } } var s = myself() // Create View var f = CGRect(x:0,y:0,width:200,height:200) var view = UIView

XML parsing in swift

谁说我不能喝 提交于 2019-11-28 07:33:30
问题 Can some body help me why the below code is not working.. I am testing it in Xcode.1 Playground let url:NSURL! = NSURL(fileURLWithPath:"file:///Users/sss/Documents/app.xml") var xml = NSXMLParser(contentsOfURL: url) xml?.parse() 回答1: Playgrounds are sandboxed, so you won't be able to just grab files from anywhere in your user folder. Here's how to add that file to your playground to make it accessible: Find your ".playground" file in the Finder Right click and choose "Show Package Contents"

How to create and send the json data to server using swift language

最后都变了- 提交于 2019-11-28 07:04:10
I'm new to IOS development and I have started with the swift language. I'm trying to get the value from two text fields and convert those two text fields into json and send that json to the server receive.php. lets concider that tow text fields are - name - pass how do i create a Json & send that to server when a button is clicked ? By using http POST method with NSURLSession. Let's say you are calling submitAction method on the press of the login button Swift 3 @IBAction func submitAction(_ sender: UIButton) { //declare parameter as a dictionary which contains string as key and value

Does swift playground support UIKit?

北慕城南 提交于 2019-11-28 04:16:44
I tried to create a UILabel in playground but failed. Does playground only support OS X development for now? YES, it does! File: New > File... > iOS > Source > Playground import UIKit let lbl = UILabel(frame: CGRectMake(0, 0, 300, 100)) lbl.text = "Hello StackOverflow!" Then, save the file. This will trigger the Playground to interpret UI related things. Sometimes you may need to toss in a trailing newline and save again -- its a beta. At this point, the word "UILabel" should appear on the right-hand side. Now, to actually view what you've done, you've got to click on the "Quick View" eye on

How to use cocoapods with playground?

邮差的信 提交于 2019-11-28 03:57:21
I am trying out some pods before I implement it with my main project I want to make sure it works properly for my requirement. Easiest way is to try it with playground. I tried pod init with playground which doesn't work [!] No xcode project found, please specify one Help is much appreciated. jkistler This is an old question but shows up at the top of Google. This Could Be Us But You Playing is a command line tool that creates a new Xcode playground with an integrated cocoapod. It also supports integrating multiple cocoapods at once. It's a single command. To Install: gem install cocoapods

“no such module” when Importing pods in swift playground

折月煮酒 提交于 2019-11-28 02:35:46
问题 Using Xcode 7.2.1. I am following this tutorial to get pods working in playground. i have added the playground into the workspace, and the podfile is linking to the playground. But importing still does not work - "no such module" https://littlebitesofcocoa.com/138-using-cocoapods-in-xcode-playgrounds // import does not work // Podfile target 'spaceships' do end platform :ios, '9.0' use_frameworks! link_with 'spaceships', 'imports', 'test' https://github.com/mingyeow

Change in Xcode 10 Playgrounds Variable Initialization change? Are Xcode 10 Playgrounds an interpreter?

梦想与她 提交于 2019-11-28 01:25:48
I've noticed that Playgrounds in Xcode 10 no longer allow for the use of declared, but uninitialized variables. For example: while this code would work in an Xcode 9 playground, in an Xcode 10 playground (at least in Beta 1), it crashes: var myValue: Int //... myValue = 100 print (myValue) // Xcode 9 prints 100 // Xcode 10 reports an error: variables currently must have an initial value when entered at the top level of the REPL Is this the new behavior, or just a bug in the current Xcode 10 beta? I had been referring to earlier Xcode Playgrounds as an interpreter, but would one still consider

Class 'ViewController' has no initializers in swift

两盒软妹~` 提交于 2019-11-27 20:57:39
Getting the complaint from the compiler when I am doing this class ViewController: UIViewController { var delegate : AppDelegate override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //self.appDelegate = UIApplication.sharedApplication().delegate; } @IBAction func getData(sender : AnyObject) { } @IBAction func LogOut(sender : AnyObject) { } } However, if I just add ? at the end of AppDelegate like below and the error is gone. class ViewController: UIViewController { var delegate : AppDelegate? override func viewDidLoad() {

Could not find an overload for '/' that accepts the supplied arguments

百般思念 提交于 2019-11-27 20:08:25
问题 // Playground - noun: a place where people can play func getAverage(numbers: Int...) -> Double{ var total = 0 var average:Double = 0 for number in numbers{ total = total + number } average = total / numbers.count return average } getAverage(3, 6) I get an error on average = total / numbers.count Could not find an overload for '/' that accepts the supplied arguments I tried to fix by doing: average = Double(total/numbers.count) but then the getAverage was set to 4 instead of 4.5 回答1: There are

How do I make an UIImage/-View with rounded corners CGRect (Swift)

谁都会走 提交于 2019-11-27 20:01:27
问题 How do I make a UIImageView with rounded corners on a Swift iOS Playground? Inside it needs to be filled with a color. 回答1: let imageView = UIImageView(frame: CGRectMake(0, 0, 100, 100)) imageView.backgroundColor = UIColor.redColor() imageView.layer.cornerRadius = 8.0 imageView.clipsToBounds = true Result: 回答2: For rounded circle image frame in swift, what it worked for me was: self.profileImageView.image = UIImage(named:"profileUser") self.profileImageView.layer.cornerRadius = self