swift2

How to add protocol type as subview

旧巷老猫 提交于 2019-12-13 19:24:30
问题 So I wrote a simple protocol: protocol PopupMessageType{ var cancelButton: UIButton {get set} func cancel() } and have a customView: class XYZMessageView: UIView, PopupMessageType { ... } and then I currently have: class PopUpViewController: UIViewController { //code... var messageView : CCPopupMessageView! private func setupUI(){ view.addSubview(messageView) } } But what I want to do is: class PopUpViewController: UIViewController { //code... var messageView : PopupMessageType! private func

Is there a limit on the number of devices on which we can launch our app using the free apple developer account?

你。 提交于 2019-12-13 19:20:48
问题 Is there a limit on the number of devices on which we can launch our app using the free apple developer account? I am using Xcode 7.3 and iOS 9.3.2 I am able to launch my app on few devices, but I always get code signing issue when I try to launch it on another new device. I tried checking the apple developer page, but could not find info regarding this. 回答1: There is no limit to the number of devices you can build on with a free account. (At least, there is no published limit.) As a side

How to use #selector in Swift 2.2 for the first responder, without a class?

偶尔善良 提交于 2019-12-13 19:16:47
问题 I want to send doSomething to the firstResponder , which could be any of several objects. menuItem = NSMenuItem(title: "Do Something!", action: Selector("doSomething"), keyEquivalent: "") I was using Selector("doSomething") prior to Swift 2.2. How do I do it now? 回答1: Create a protocol with the Selector doSomething and have all of your objects that can be first responders conform to it. Then implement the selector for your classes. @objc protocol MyProtocol { func

Error trying to perform a GET request in swift 2.0

我与影子孤独终老i 提交于 2019-12-13 18:23:51
问题 So I'm trying to perform a GET request in Swift 2.0, and after migrating a few lines of code from my Swift 1.2 I'm getting this error that I'm not really understanding how to bypass it / migrate it correctly. The function is written as the following: func performGetRequest(targetURL: NSURL!, completion: (data: NSData?, HTTPStatusCode: Int, error: NSError?) -> Void) { let request = NSMutableURLRequest(URL: targetURL) request.HTTPMethod = "GET" let sessionConfiguration =

Swift 2 - Share video with UIActivityViewController

吃可爱长大的小学妹 提交于 2019-12-13 13:04:27
问题 I am trying to share a video from a URL using UIActivityViewController . If I try with an Image I have not problems. Share Image Works: let imageThump = NSURL(string: "https://example.com/image.png") let imageData = NSData(contentsOfURL: imageThump!) let objectsToShare = [comment!, imageData!] let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil) Share Video is not working. Why? let videoShare = NSURL(string: "https://example.com/video.mp4") let

How can I create a .swift file for my new .sks file?

依然范特西╮ 提交于 2019-12-13 12:50:58
问题 When using Xcode, I've faced the annoying problem, which is Xcode always crashes when I click .SKS files. I have raised questions here, and even in Apple developer forum, as well as searched for the solutions on the Internet... but it is hopeless. Because I am making a game with many scenes, so if I can't use SpriteKit editor to interact with the scenes in an easy way, I want to know how can I interact with my scenes by coding their .swift files. So the question is, for example, when I create

How to test method that throws error in Swift 2?

我们两清 提交于 2019-12-13 11:56:54
问题 This is my method definition: func isValidForMode(mode: DBFindViewControllerMode) throws -> Bool { } Now I can test this in simple way, since I know that it DO NOT throws an error: XCTAssertTrue(try! searchOptionsManager.isValidForMode(.Address)) But what if I know that method throws? The best solution would be XCTAssertThrows() , but it is not:-) Below is my try: do { try searchOptionsManager.isValidForMode(.Address) } catch let error { XCTAssertEqual(error as! DBErrorType, DBErrorType

sendSynchronousRequest is deprecated in ios 9 [duplicate]

蓝咒 提交于 2019-12-13 11:25:19
问题 This question already has an answer here : Fixing NSURLConnection Deprecation from Swift 1.2 to 2.0 (1 answer) Closed 4 years ago . Xcode says that sendSynchronousRequest is now deprecated. How should I replace it? let postData:NSData = post.dataUsingEncoding(NSASCIIStringEncoding)! let postLength:NSString = String( postData.length ) let request:NSMutableURLRequest = NSMutableURLRequest(URL: url) request.HTTPMethod = "POST" request.HTTPBody = postData request.setValue(postLength as String,

Update code to swift 2 [closed]

江枫思渺然 提交于 2019-12-13 11:21:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . How do i update following code to swift 2 i am new if let rtf = NSBundle.mainBundle().URLForResource("rtfdoc", withExtension: "rtf", subdirectory: nil, localization: nil) { let attributedString = NSAttributedString(fileURL: rtf, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes

Try and catch Error with Parse.com

荒凉一梦 提交于 2019-12-13 10:25:11
问题 I need some help with this: func checkUserCredentials() -> Bool{ PFUser.logInWithUsername(userName!, password: Contraseña!) if (PFUser.currentUser() != nil){ return true } return false } It says that PFUser.logInWithUsername(userName!, password: Contraseña!) has problems because its not marked with try ... and the error is not handled. 回答1: func checkUserCredentials() -> Bool{ do { try PFUser.logInWithUsername(userName!, password: Contraseña!) } catch{ // deal here with errors } return PFUser