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 8361583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:43:53+00:00 2026-06-09T11:43:53+00:00

Everytime i run the code it run in infinite loop and call the function

  • 0

Everytime i run the code it run in infinite loop and call the function myProperty over and over again. What should i do to overcome this..I have written the following code in viewDidLoad function of the viewController.

[self.model addObserver:self forKeyPath:@"myProperty" options:NSKeyValueObservingOptionNew context:NULL];

[self.model myProperty];

here i have a Model class and it has a property named myProperty and a method or a getter myProperty.I am usingmyProperty to connect to a database a collect all the values of a column and store it in myProperty. I have checked myProperty method..it is doing fine without KVO. But when i add this KVO this goes into infinite loop.

again i have also used

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{

if([keyPath isEqualToString:@"myProperty"])

NSLog(@"called");

}

and my myProperty method is

- (void) myProperty
{

NSString *file = [[NSBundle mainBundle] pathForResource:@"MyDatabase" ofType:@"db"];

    sqlite3 *database = NULL;


sqlite3_stmt *stmt;



NSMutableArray *availableNames=[NSMutableArray array];


if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) 
{


    NSString *query=[NSString stringWithFormat:@"select * from Names"];


    if(sqlite3_prepare_v2(database, [query UTF8String], -1, &stmt, NULL)==SQLITE_OK)
    {


        while (sqlite3_step(stmt)==SQLITE_ROW) {




            [availableNames addObject:[[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(stmt,1 )]];
        }


        sqlite3_finalize(stmt);

        }

}
sqlite3_close(database);

self.myProperty = availableNames;


}

Thank you in advance

  • 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-06-09T11:43:54+00:00Added an answer on June 9, 2026 at 11:43 am

    First, rename getMyProperty to simply myProperty. Methods should not be prefixed with get.

    Secondly, you need to post the implementation of getMyProperty and post part of the backtrace of the infinite loop. Most likely, your getter is triggering a mutation which is triggering KVO which triggers the getter which triggers the mutation which triggers KVO….


    self.myProperty = availableNames;
    

    That’s your problem right there; you are changing state from your getter which leads to the infinite loop described above. Getters really shouldn’t be that complex; do you really want to open a database connection and read from disk every single time you ask for the available names? Slow!

    Split that out; create a loadAvailableNames method that can be called at an appropriate time (if (self.needsLoading) [self loadAavailableNames]; return _myProperty;, etc…).

    Also — writing against the raw SQLite API is both a waste of time and really hard to get right. If you need portability of database, use something like FMDB. If you want to maximally leverage system capabilities, use Core Data.

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

Sidebar

Related Questions

Everytime I run this code, the console goes into an infinite loop printing Please
I'm getting a segmentation fault everytime i want to run this code : from
Everytime I run the program, this mysterious error pops up saying that I have
I've tried to run this code under scala 2.7.3 and 2.7.7 and everytime i
I have this code for my app, it doesn't show any errors but everytime
I have this code: <script language=javascript> $(function() { $('#items,#button-search').hide(); $(#companies).click(function() { $(this).attr(value,); $('#address,#new-company-form').empty(); });
im really desperate right now, ive tried everything. Everytime i run my app this
I have this warning every time I run my CGI-script (output is rendered by
I'm new to WPF, and I get error everytime I run my code DoubleAnimation
Here is my source code and it keeps force closing everytime I run it...

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.