Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access property from class

//MigrationVC.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface MigrationVC : UIViewController

@end

//MigrationVC.m
#import "MigrationVC.h"

@interface MigrationVC()
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIProgressView *progressView;

@end

@implementation MigrationVC

@end

//CoreData
#import "CoreData.h"
#import "MigrationVC.h"

@interface CoreData()
@property (nonatomic,retain) MigrationVC *migrationVC;
@end

-(void)obsererForKeyPath:(NSString*)keyPath object:(id)object change:(NSDictionary*)change context:(void*)context
{
    if([keyPath isEqualToString:@"migrationProgress"])
    {
        dispatch_async(dispatch_get_main_queue(),^{
            float progress=[[change objectForKey:NSKeyValueChangeNewKey] floatValue];
            self.migrationVC.progress=progress;
        });
    }
}

I am trying to learn CoreData and migration right now but this is giving me a quite a headache.

I am trying to access the outlet properties from another classes but always gives red warning (Property 'label' not found on object of type MigrationVC*).

I tried adding a NSString property in .h file which was accessible but when i tried to change the outlet from .m to .h file i couldn't ctrl+drag the view in the .h file.

I never had this problem. I have accessed outlet from .m file many times in the past but it just gives me warning now. How can i access the properties while outlet in .m file?

The problem is i can't add the outlet in .h file

I cannot outlet the properties in .h file.

like image 414
hengecyche Avatar asked Sep 17 '25 09:09

hengecyche


1 Answers

You have to transfer you outlet properties from .m file to .h file (copy and paste). If you want your properties to be public so they have to be declared in header file. If you want them to be private - declare them in implementation file.

//MigrationVC.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface MigrationVC : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIProgressView *progressView;
@end

//MigrationVC.m
#import "MigrationVC.h"

@interface MigrationVC()

@end

@implementation MigrationVC

@end
like image 133
fnc12 Avatar answered Sep 20 '25 01:09

fnc12