PFTwitter Utils for Swift - 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

Related

Cannot select IBOutlet in connections

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.

'Storyboard doesn't contain a view controller with identifier 'TimeController'' error in Swift

I am trying to send an Int from one view controller to another in swift, but I am getting this error. There is another post on this same topic, but the advice given is to 'clean' the project which does not work for me. Here is my code:
First view controller:
import UIKit
class UserInput: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
var myInt = Int()
override func viewDidLoad() {
super.viewDidLoad()
myInt = 5
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func submit(_ sender: Any) {
let myVC = storyboard?.instantiateViewController(withIdentifier: "TimeController") as! TimeController
myVC.intPassed = myInt
navigationController?.pushViewController(myVC, animated: true)
}
}
Second view controller:
import Foundation
import UIKit
class TimeController: UIViewController {
var intPassed = Int()
override func viewDidLoad() {
super.viewDidLoad()
print(intPassed)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Ensure you have inserted TimeController as the Storyboard ID in your 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)
}
}

Linking View Controllers through button

I'm a beginner at all of this...Having said that I've come across a point in my app where I've stalled and don't know what to do or fix next. So any answers would be appreciated!
So in my Home View Controller, I have four buttons with four different categories.
Each of these categories has its own question list, but they have a common "General Question" list. The general question list has its own view controller.
When you click on any of the four buttons, it brings you to the General Question view. At the bottom of this view, I have a "Next" button.
Goal: Configure the Next button to continue to one of the category's question list based on what is initially pressed in the Home View Controller.
I've connected the buttons via outlet and action in the View Controller.
However, the Next button will not connect when I control + drag into the View Controller. I'm not sure where I need to put the code for this...
I was thinking that the code for the Next button might need to have some kind of conditional statement, but since it won't connect I can't even get that far.
Help!
(This is what I have) Sample Code:
import UIKit
import AddressBookUI
import AddressBook
import Foundation
import CoreData
import CoreGraphics
import EventKit
import EventKitUI
import CoreFoundation
class ViewController: UIViewController {
#IBOutlet var ColorButton: UIButton!
#IBOutlet var StyleButton: UIButton!
#IBOutlet var CutButton: UIButton!
#IBOutlet var MakeupButton: UIButton!
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.
}
var eventstore: EKEventStore!
var event: EKEvent!
weak var editViewDelegate: EKEventEditViewDelegate!
#IBAction func ColorButtonPressed(sender: UIButton) {
}
#IBAction func StyleButtonPressed(sender: UIButton) {
}
#IBAction func HaircutButtonPressed(sender: UIButton) {
}
#IBAction func MakeupButtonPressed(sender: UIButton) {
}
}
Here is a suggested approach as shown in the code below for 2 controllers (instead of 4) for brevity. Use appropriate named segues to each of the "next processing" controllers from the common processing controller and set up a chain. Here is a link to the project file: Project file
import UIKit
class ViewController: UIViewController {
var nextVcId = 0 // defines the button that is pressed
#IBAction func unwindFromOtherControllers(segue: UIStoryboardSegue) {
// In case you want to get back to the main VC
}
#IBAction func btn2Action(sender: UIButton) {
nextVcId = 0
self.performSegueWithIdentifier("commonSegue", sender: sender)
}
#IBAction func btn1Action(sender: UIButton) {
nextVcId = 1
self.performSegueWithIdentifier("commonSegue", sender: sender)
}
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.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let vc = segue.destinationViewController as! CommonViewController
vc.nextControllerId = nextVcId
}
}
import UIKit
class CommonViewController: UIViewController {
var nextControllerId = 0
#IBOutlet weak var StatusLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.StatusLabel.text = "Common"
commonProcessing()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func commonProcessing() {
// do your common processing
if nextControllerId == 0 {
performSegueWithIdentifier("next1Segue", sender: self)
} else {
performSegueWithIdentifier("next2Segue", sender: self)
}
}
}
import UIKit
class Next1ViewController: UIViewController {
#IBOutlet weak var statusLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.statusLabel.text = "Next1"
next1Processing()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func next1Processing() {
println("Next 1 Processing")
}
}
import UIKit
class Next2ViewController: UIViewController {
#IBOutlet weak var statusLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
statusLabel.text = "Next 2"
next2Processing()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func next2Processing() {
println("Next 2 Processing")
}
}
processing