0

I have objc code (SUOTAViewController) that I am including in my Swift project. I also have a storyboard associated with that ViewController with the storyboardID "suotaViewController".

When I try to instantiate it like this:

func navigateToUpdateViewController(imageURL: URL) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "suotaViewController") as! SUOTAViewController
        vc.imageURL = imageURL
        self.navigationController?.pushViewController(vc, animated: true)
    }

I get an error "Could not cast value of type 'UIViewController' to 'SUOTAViewController'

Why is this happening?

Here is my SUOTAViewController if it helps:

#define UIALERTVIEW_TAG_REBOOT 1

#import "SUOTAViewController.h"

@interface SUOTAViewController ()

@end

@implementation SUOTAViewController

@synthesize blockSize;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textView.text = @"";
    
    storage = [ParameterStorage getInstance];
    manager = storage.manager;
    storage.file_url = self.imageURL;
    
    [self.progressView setProgress:0];
    [self.progressTextLabel setText:[NSString stringWithFormat:@"%d%%", 0]];
    
    // Enable notifications on the status characteristic
    [manager setNotifications:GenericServiceManager.SPOTA_SERVICE_CBUUID characteristicUUID:GenericServiceManager.SPOTA_SERV_STATUS_CBUUID enable:YES];
} ...

I have already set the class of the ViewController in the storyboard to "SUOTAViewController" which matches that of my Obj-C ViewController. I am still getting the error.

Dylon Jaynes
  • 166
  • 11
  • Did you set the type of the VC correctly in the storyboard? Does the same code in Obj-C work? – Dávid Pásztor Sep 23 '22 at 16:17
  • @DávidPásztor the Main.storyboard type is "Default - Interface Builder". I don't know if the same code works in Objc. I – Dylon Jaynes Sep 23 '22 at 16:21
  • I'm not asking about the type of the storyboard. Inside the storyboard, when you select the view controller and set its identifier, you also have to set its type - by default, it's just `UIViewController`. – Dávid Pásztor Sep 23 '22 at 16:22
  • @DávidPásztor That makes sense but I don't see an option in Xcode to set the type. How do I find that? – Dylon Jaynes Sep 23 '22 at 16:25

0 Answers0