Cannot select IBOutlet in connections - swift

Im trying to make a simple app but am unable to make an IBOutlet like I was able to before, now you don't have the option in swift to change the connection to an Outlet instead of an action. I believe this could be because of the update in the Software as it is now Swift version 9.1. Thank you in advance!
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

You have dragged to the exit on the view controller. Drag directly (ctrl) from the storyboard to the code.

Related

Why do IBOutlets only respond to one of the multiple view controllers?

I have multiple ViewControllers in my storyboard, and I need various objects in the story board to link to vars in my code.
Screenshot of my ViewControllers
I'm only able to ctrl + drag an IBOutlet from the ViewController I initially began with, and changing the story entrance point doesn't affect the problem.
Code I am trying to link
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#objc func didTapButton(_ tap: UITapGestureRecognizer) {
}
}
extension ViewController: UIViewControllerTransitioningDelegate {
}
Make sure you specified the correct "Custom Class" for each of your view controllers.
That is, set ViewController as the custom class for each of your view controllers.
Like this:
Link the UIView class you want to connect with the UIView in the storyboard.

'NSInternalInconsistencyException', reason: 'Only run on the main thread!' swift 4

hey guys just wondering if you could help me debug this, this error comes up but only when i add a ui text view to a view controller here is everything i have for the view controller code as you can see i tried dispatchQueue but doesn't do anything.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
weak var textview: UITextView!
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Declare variable out side the viewDidLoad
import UIKit
class ViewController: UIViewController {
var textview: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
It looks like you're working with this controller from not-main thread. I think that you're trying to show the controller from some closure or async call. You have to ensure that your UI calls only from main thread.
Also you can debug it. Before you create/instantiate this controller set breakpoint and pay attention on debug navigator in XCode, you will be able to see where the program stopped, is this main thread or not.

UIAlertController willDismiss alternative

I haven't done much iOS development in a while and while updating an old project I came across a question I couldn't find an answer for.
What is the replacement for
actionSheet:willDismissWithButtonIndex:
(emphasis on WILL)
I have some animation code that needs to execute at this point and currently I can only see how to execute my code after the sheet has been dismissed.
I'm sure the answer is right in front of my face, I just can't see it.
You can create a custom UIAlertController with a delgate and use that
import UIKit
#objc protocol CustomAlertControllerDelegate {
#objc optional func CustomAlertControllerWillDismiss(controller: CustomAlertController)
}
class CustomAlertController: UIAlertController {
weak var delegate:CustomAlertControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.delegate?.CustomAlertControllerWillDismiss!(controller: self)
}
}

Reveal Passcode dots using Swift

How do I reveal the passcode dots in swift, so then the user can see their password by clicking a button.
Thanks
Tyge
TextField has a property called secureTextEntry. All you need is to connect an outlet to your textfield and toggle secureTextEntry:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var passwordField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
passwordField.secureTextEntry = true
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func showHide(sender: UIButton) {
passwordField.secureTextEntry = !passwordField.secureTextEntry
sender.setTitle({passwordField.secureTextEntry ? "Show":"Hide"}(), forState: .Normal)
}
}
stackoverflow provides a working search engine, but anyway here you is the answer.
Do the same, but with false instead of true
Obscure a UITextField password
By the way make sure that the user knows what he does when reveal the secure text.

PFTwitter Utils for Swift

racking my brain on this one but I am unable to get the PFTwitterUtils to work within swift.
I have imported all the relevant files from Parse (including PFTwitter Utils)
but it just won't recognise it for me to create an instance.
Does anyone know why this is happening? this is all I have so far
import UIKit
import Parse
import Foundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func loginWithTwitter(sender: AnyObject) {
PFTwitterUtils
}
}
Add import ParseTwitterUtils on the top of your ViewController