Just Someone
Just Someone

Reputation: 253

Assistant Editor shows different "ViewController.swift" file than the one that Main Editor shows?

The source code shown in the Assistant Editor for "ViewController.swift" is different than source code shown in Main Editor for "ViewController.swift".

"ViewController.swift" in Main Editor:

//  ViewController.swift
//  FoodTracker

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {
    // MARK: Properties
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var mealNameLabel: UILabel!
    @IBOutlet weak var mainButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        nameTextField.delegate = self
    }

    // MARK: UITextFieldDelegate
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }

    func textFieldDidEndEditing(textField: UITextField) {
        mealNameLabel.text = textField.text
    }

    // MARK: Actions
    @IBAction func setDefaultLabelText(sender: UIButton) {
        mealNameLabel.text = "DEFAULT text"
        // mainButton.tintColor = UIColor.darkTextColor()    
    } 
}

"ViewController.swift" in Assistant Editor:

//
//  ViewController.swift
//  FoodTracker
import UIKit

internal class ViewController : UIViewController, UITextFieldDelegate {

    @IBOutlet weak internal var nameTextField: UITextField!
    @IBOutlet weak internal var mealNameLabel: UILabel!
    @IBOutlet weak var mainButton: UIButton!

    override internal func viewDidLoad()

    internal func textFieldShouldReturn(textField: UITextField) -> <<error type>>

    internal func textFieldDidEndEditing(textField: UITextField) -> <<error type>>

    @IBAction internal func setDefaultLabelText(sender: UIButton) -> <<error type>>
}

So, those are completely different different files, but have the same name. The one in the Assistant Editor is the interface while the file shown in the Main Editor is the implementation of the interface, right?

That seems a little weird, but the interface and implementing class have the same name? When I'm working in Xcode I need to be aware that sometimes two files can (often?) have the same name?

Upvotes: 3

Views: 3254

Answers (4)

Valter Ekholm
Valter Ekholm

Reputation: 335

I have seen what could be a solution at the video youtube.com/watch?v=wPAUKhlmW1M at time-position 1:31 - please correct if I'm wrong

Changing custom class from default viewcontroller

Upvotes: 0

andrewlewisdev
andrewlewisdev

Reputation: 232

(Swift 4.2) I just had the same problem. Whenever I was in the assistant editor, my ViewController was labeled internal and I couldn't make any edits to it. The above solutions didn't work for me, but they put me on the right trail. Apparently, I was in some kind of duplicate file and not in the ViewController I needed. Correcting the issue was simply a matter of navigating to the correct file via the controls at the top of the assistant editor.

enter image description here

enter image description here

Upvotes: 1

OmniB
OmniB

Reputation: 111

I found this in Xcode 9.2, Swift 4, but it may be in other versions.

In Xcode, with the option key down, hover your mouse over 'func' or another scope-describing keyword to reveal the scope with the blue bracket.

Then do a two finger tap on the trackpad to automatically open an Assistant Editor at the same point in the code. I'm frequently going somewhere else in my code but want to have a window open that stays where I just was. This trick does just that.

enter image description here

(Make sure your track pad is set so a 'Secondary click' is a tap with two fingers.)

Upvotes: 1

toast
toast

Reputation: 1980

I had the same problem. I couldn't figure out why it was showing this "internal class" file.

I managed to get it to display the correct associated file. To do this, click the associated editor icon, the two circles. Then in the window that appears, click the '+'. The new window that appears should have the right code in it. Then close the old window and you should be left with the right one. The rest of the project appears to work be fixed now.

Upvotes: 5

Related Questions