Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3431660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:21:14+00:00 2026-05-18T07:21:14+00:00

In my app , i created my custom class and i am observing one

  • 0

In my app , i created my custom class and i am observing one of its property using KVO ,so that if its value changed it instantly display in firstview controller object (label or .. )

sample code

myCustomClass.h

@interface myCustomClass : NSObject {
    NSString * text;
}
@property (nonatomic, retain) NSString * text;
- (void)changetext;

myCustomClass.m

@implementation myCustomClass

@synthesize text;
static myCustomClass * _sharedInstance;

- (id)init
{
    if ((self = [super init])) {
        text = @ "";
    }
    return self;
}

+ (myCustomClass *)sharedInstance
{
    if (!_sharedInstance) {
        _sharedInstance = [[myCustomClass alloc] init];
    }

    return _sharedInstance;
}
- (void)changetext {
    text = @ "changed";
}

firstViewController.h

@interface FirstViewController:UIViewController {

    IBOutlet UILabel * label;
}
@property (nonatomic, retain) IBOutlet UILavel * label;

firstviewController.m

@implementation FirstViewController

@synthesize label;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id) object change:(NSDictionary *)change context:(void *)context
{
    label.text = [change valueForKey:@ "new"];
}
- (void)viewDidLoad {
    myCustomClass * myEngine = [myCustomClass sharedInstance];
    [myEngine addObserver : self forKeyPath : @ "text" options : NSKeyValueObservingOptionNew context : nil];
    [myEngine changetext];

    [super viewDidLoad];
}

but its not changing the data , can any one please tell me where i am wrong ?

thanks in advance

P.S : i wrote in hurry forgive me if any mistakes in writing and sorry for my bad english .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:21:14+00:00Added an answer on May 18, 2026 at 7:21 am

    When you assign to an instance variable directly rather than going through a setter, you need to issue change notifications yourself with willChangeValueForKey: and didChangeValueForKey:. There’s no magic to variable assignment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app i have created one custom class for Label.Now i want to
I'm using google app engine/python. And I have created a custom datatype and property.
I have created a flexible navigation bar in my app that will show custom
I have created a windows phone 7 custom class library, in that I have
Using Google App Engine (python SDK), I created a custom JSONProperty() as a subclass
I've created a custom control (a class that inherits from Control). When I put
I've created a custom cell class using these instructions: http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder/ Everything worked great, except
i'm trying to make a custom Gallery in my app. I created a class
I've created a custom method called checkout in my app. I create an order
I've created a custom keyboard with my own Unicode characters... The app works great

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.