-1

Extremely new to Swift and Objective C. My manager has tasked me with reposting an outdated app back onto the app store. It was removed due to some Apple updates and our app didn't meet the new qualifications. But I've been having issues just trying to compile the project. So I by first updating the project by running updates on its old software like XCode. But now I'm stuck at this issue of the AppDelegate Swift functions can't be seen in the objective C code. However, when I right-click and go to definition, it has has no problem finding them. This is one example.

Objective C

Swift

  • 3
    Please include code, not pictures of code, which can't be copied/pasted, searched, or read by screen readers – jnpdx Oct 10 '22 at 02:54
  • Most of the classes are in objective c. But your AppDelegate is in swift. Why you selected swift for project. It's better to go with objective-c. If you want to your code in swift for future purpose, it's better to rewrite objective-c code in swift. – phani Oct 10 '22 at 08:09

3 Answers3

0
  1. You need to add @objc as prefix for variables or functions which you would like to access from Swift file to Objective C or mark class as @objcMembers if you want to access everything from swift file to Objective c

  2. make sure you have created a bridging header file. Here is helper link

  3. You need to import that bridging header in your Objective C file.

If you have do all three steps as mentioned, you will be able to access that function.

Pushkraj Lanjekar
  • 2,254
  • 1
  • 21
  • 34
0

In your code you are accessing instance methods as class methods

Error itself saying that

No known class method for selector 'myBlue'

Follow below steps

@property(nonatomic,strong) IBOutlet AppDelegate *appDelegate; // .h file

self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; // .m file. //ViewDidLoad Method

Now you can access method as

[self.appDelegate myBlue]

Else

[delegate myBlue] // as per your code

Finally you need to know difference between Class & Instance Methods

-(void)someInstanceMethod{
    //Whatever you want your instance method to do here
}

+(void)someClassMethod{
    //Whatever you want your class method to do here
}

FYI :

Also if you want to use Swift Files in Objective-C Files or mix of it, you need to have BridgeHeader File

Follow answer suggested by @Pushkraj Lanjekar

Hope it helps.

Vidhyanand
  • 5,369
  • 4
  • 26
  • 59
0

The AppDelegate is a Swift file and you need to import it to an Objective-C file. Check the Apple's guide importing swift into Objective-C, you need to:

  1. Import the genareted Swift header to the SettingsViewController.m

    #import "ThinkNotes-Swift.h"

If the module name is not ThinkNotes then replace that with your projects module name.

  1. Make sure the Swift classes you need to access from Objective-C have the @objc attribute in their declaration.
Christos Koninis
  • 1,499
  • 1
  • 15
  • 28