Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS unknown typename appdelegate

I am receiving error like

: Unknown type name 'AppDelegate'

: Unknown type name 'AppDelegate'

: Property with 'weak' attribute must be of object type

Error Image

I had refer many Question like this but all give answer like add

@class Appdelegate;

I tried with editing this code but after this it gives error like

: AppDelegate.m:23:18: Redefinition of 'ddLogLevel'

Refined Log

Because this log is define in both view controller. i have also tried to commented line of this log from above view controller but then it will give error

: /ChatViewController.m:440:13: Use of undeclared identifier 'ddLogLevel'

DDLOG Error

Now what is the solution for this?

EDIT: i have to declare like this. because i am working on xmpp. so i have to call [[self appDelegate] connect] method in another view controller.

- (AppDelegate *)appDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}

EDIT

      //Appdelegate.h file //
    #import <UIKit/UIKit.h>
    #import <CoreData/CoreData.h>
    #import "ViewController.h"
  #import "MBProgressHUD.h"
  #import "FriendsViewController.h"
  #import <CoreData/CoreData.h>
 #import "XMPPFramework.h"
//@class FriendsViewController;
@class ViewController;
   @interface AppDelegate :  NSObject <UIApplicationDelegate, XMPPRosterDelegate>
 {
XMPPStream *xmppStream;
XMPPReconnect *xmppReconnect;
XMPPRoster *xmppRoster;
XMPPRosterCoreDataStorage *xmppRosterStorage;
XMPPvCardCoreDataStorage *xmppvCardStorage;
XMPPvCardTempModule *xmppvCardTempModule;
XMPPvCardAvatarModule *xmppvCardAvatarModule;
XMPPCapabilities *xmppCapabilities;
XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;

NSString *password;

BOOL customCertEvaluation;

BOOL isXmppConnected;
BOOL isauthenticate;

UIWindow *window;
UINavigationController *navigationController;
//SettingsViewController *loginViewController;
UIBarButtonItem *loginButton;
ViewController *viewController;
FriendsViewController *FriendsViewController;
  }
 @property (strong, nonatomic) UIWindow *window;
 @property (nonatomic, strong, readonly) XMPPStream *xmppStream;
 @property (nonatomic, strong, readonly) XMPPReconnect *xmppReconnect;
 @property (nonatomic, strong, readonly) XMPPRoster *xmppRoster;
 @property (nonatomic, strong, readonly) XMPPRosterCoreDataStorage  *xmppRosterStorage;
 @property (nonatomic, strong, readonly) XMPPvCardTempModule *xmppvCardTempModule;
 @property (nonatomic, strong, readonly) XMPPvCardAvatarModule *xmppvCardAvatarModule;
 @property (nonatomic, strong, readonly) XMPPCapabilities *xmppCapabilities;
 @property (nonatomic, strong, readonly) XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;

//@property (nonatomic, strong) IBOutlet UIWindow *window;
@property (nonatomic, strong) IBOutlet UINavigationController *navigationController;
//@property (nonatomic, strong) IBOutlet SettingsViewController *settingsViewController;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *loginButton;
@property (nonatomic, strong) ViewController *viewController;
@property (nonatomic, strong) FriendsViewController *FriendsViewController;
  - (NSManagedObjectContext *)managedObjectContext_roster;
  - (NSManagedObjectContext *)managedObjectContext_capabilities;
  @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
  @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
  @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
  - (BOOL)connect;
  - (BOOL) isXmppConnected;
  - (void)disconnect;
  -(BOOL) isauthenticate;

 @end
like image 213
Badal Shah Avatar asked Jan 17 '26 06:01

Badal Shah


2 Answers

You have two issues there, I will address them separately:

Unknown type name 'AppDelegate'

This occurs because of circular dependency: ChathistryViewController.h imports AppDelegate.h and vice-versa.

You can resolve this by importing AppDelegate.h only in ChathistryViewController.m and including @class AppDelegate in .h file.

AppDelegate.m:23:18: Redefinition of 'ddLogLevel'

When you are defining ddLogLevel in your *ViewController.h file, it's definition is "copied" to all files you import *ViewController.h.

You should import CocoaLumberjack and define ddLogLevel only in .m files, as they are not needed in .h anyway.

like image 121
Jakub Vano Avatar answered Jan 19 '26 20:01

Jakub Vano


Appdelegate object should be created like this:

It is a singletone Class, where only one instance of the class exists for the current process.

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
like image 22
Mumthezir VP Avatar answered Jan 19 '26 18:01

Mumthezir VP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!