swift2

Ambiguous reference to member Swift 3

人盡茶涼 提交于 2020-03-13 06:04:06
问题 I am migrating my project from Swift 2.3 to Swift 3. And having difficulty as expected. Here is a function which is being used for OAuth, using OAuthSwift. I have tried to convert class func OAuthSwiftAuthorization(inViewController viewController: UIViewController, withOAuthInfo info:FitnessTracker, successHandler:@escaping MyOAuthNewSuccessHandler, failure: @escaping ((_ error: NSError) -> Void)) { let oauthswift = OAuth2Swift( consumerKey: info.consumerKey, consumerSecret: info

Size image pin annotation

冷暖自知 提交于 2020-02-18 05:01:26
问题 I put the personal image instead of the traditional red pin. When I open the map to display the pin, the image cover the entire map. Is there a maximum size of the pin image or how do I integrate something in the code to fit the size standard classic pin? func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { if annotation is MKUserLocation { return nil } let annotationIdentifier = "SomeCustomIdentifier" // use something unique that functionally

Size image pin annotation

假如想象 提交于 2020-02-18 04:56:35
问题 I put the personal image instead of the traditional red pin. When I open the map to display the pin, the image cover the entire map. Is there a maximum size of the pin image or how do I integrate something in the code to fit the size standard classic pin? func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { if annotation is MKUserLocation { return nil } let annotationIdentifier = "SomeCustomIdentifier" // use something unique that functionally

How to set contactDelegate for physicsWorld in SpriteKit?

我的梦境 提交于 2020-02-06 23:32:11
问题 I have just encountered a problem when assigning contactDelegate to self (GameScene). override func didMoveToView(view: SKView) { self.physicsWorld.contactDelegate = self /* ... */ } Unfortunately, I get an error: Cannot assign a value of type 'GameScene' to value of type 'SKPhysicsContactDelegate?' This wouldn't happen in previous versions of Xcode (probably something new in Swift 2.0), so even in SpriteKit documentation on Apple Developer they have the same code I do. How do I get around

How to set contactDelegate for physicsWorld in SpriteKit?

折月煮酒 提交于 2020-02-06 23:24:09
问题 I have just encountered a problem when assigning contactDelegate to self (GameScene). override func didMoveToView(view: SKView) { self.physicsWorld.contactDelegate = self /* ... */ } Unfortunately, I get an error: Cannot assign a value of type 'GameScene' to value of type 'SKPhysicsContactDelegate?' This wouldn't happen in previous versions of Xcode (probably something new in Swift 2.0), so even in SpriteKit documentation on Apple Developer they have the same code I do. How do I get around

What changed in xcode7 debugger that I can no longer view variables with “po” / Swift

假装没事ソ 提交于 2020-01-30 05:28:56
问题 ok what changed in xCode7 / Swift that I can no longer use "po frame" to view the contents of a CGRect anylonger? The print statment works just fine in the code. How come I can't view that in the debugger console like I used to? var frame = self.myLabel.frame frame.origin.x = self.startingFrame.origin.x + translation.x frame.origin.y = self.startingFrame.origin.y + translation.y print(frame) self.myLabel.frame = frame yet in the debugger if I break on the self.myLabel.frame = frame statement

UITextInputMode.activeInputModes() crashes in Swift 2

耗尽温柔 提交于 2020-01-30 05:25:21
问题 I want to get UITextInputMode in Swift 2 but UITextInputMode.activeInputModes() crashes. let x = UITextInputMode.activeInputModes() // crash here for t in x { print(t) } 回答1: It is a bug in Xcode 7 as mentioned HERE. Which says: Summary: Prior to the Xcode 7 GM, UITextInputMode.activeInputModes() returned an array of UITextInputMode instances. However, in the Xcode 7 GM, the method signature in the header file and documentation states that it returns an array of Strings, which is incorrect.

Generate a Random Word in Swift

*爱你&永不变心* 提交于 2020-01-29 09:24:04
问题 I am trying to explore the Swift programming language. I was searching through the Swift API and I found the UIReferenceLibraryViewController class. I found the method that returns a bool value if a word is real or not ( .dictionaryHasDefinitionForTerm ) and I also looked for a method that can return a random word. Sadly, this method does not seem to exist. I realize that I can explore 3rd party APIs, however I prefer to stay away from them if possible. I thought that maybe I could go through

Multiple Picker Views on a single view

旧巷老猫 提交于 2020-01-26 02:55:06
问题 I have followed the following SO question to create multiple picker views. It works but not exactly how I want it. What I require: My view will have multiple buttons. On tap each button will show a picker view at the bottom of the screen.Each buttons picker view will have different options. See image below: What I have done: So far I have created two buttons and then added two picker views to my storyboard. See Below The code is below: import UIKit class ViewController: UIViewController,

How to change color of single letters or one word in line

旧巷老猫 提交于 2020-01-24 13:11:06
问题 How to change color of word in "message" in AlertView @@IBAction func btn_instructions(sender: UIButton) { let alertView = UNAlertView(title: "MyTitle", message: "Here green text, here red text") alertView.show() Sorry if question is not correct. 回答1: As I've written in my comment above, UIAlertView is deprecated, so you'll have to use UIAlertController instead. You can , however, set attributed strings for the message, using (non-swifty) key-value coding (since UIAlertView is a subclass of