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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:44:34+00:00 2026-06-04T14:44:34+00:00

working on xcode I realized that if I create a non-void method, I call

  • 0

working on xcode I realized that if I create a non-void method, I call it from a class / method, the result is processed optimally only if the action is immediate. I tried to do a test by inserting a delay and I realized that it no longer works.
I will write down here the example that I created:

Class A

//--------------------CLASS A
- (void)viewDidLoad {
   [super viewDidLoad];
   i = 0;
   Class *classB = [[Class alloc] init];
   i = [classB method1];
   [self performSelector:@selector(method3) withObject:NULL afterDelay:1.8];
}

-(void)method3 {
   NSLog(@"i = %i",i); // i = 0
}

Class B

//--------------------CLASS B    
-(int)method1 {
  [self performSelector:@selector(method2) withObject:NULL afterDelay:1];
  return a;
}

-(void)method2 {
  a = 800;
}

Obviously my problem is not something so trivial but I tried to make it easy to get an answer as thoroughly as possible, I was advised to use modal methods but I don’t think that’s the solution I was looking for.

What could I do to solve this?!

  • 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-04T14:44:36+00:00Added an answer on June 4, 2026 at 2:44 pm

    What you really need is a better understanding of asynchronous methods. In your method1, the variable a is never altered — all you are doing is scheduling method2 to be called in the future and then returning the current state of variable a.

    In Objective-C, there are a few different ways you can solve this problem. People most commonly use protocols and delegates to solve this issue. Here is a basic intro to protocols and delegates. Basically, you would want your class A object to be a delegate of your class B object. You could also use NSNotifications or blocks, although you should probably understand the usage of protocols and delegates (they are very important in Objective-C) before moving on to notifications and blocks.

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

Sidebar

Related Questions

I'm working on a school project and I'm getting some weird errors from Xcode.
I have been working with Xcode 4.2.1, but following some tutorials and videos from
I'm working with xcode and I have classes associated with other projects that I
Today I just opened the project I was working on XCODE 4, and only
I'm working in XCode and I've also written an external editor tool that generates
What I'm doing: I'm working in Xcode, and started using Git not that long
While working with xcode, I saw a new line jmUIImage and i try to
I am working on xcode project intended to make a universal app.With the window
I am working on Xcode 4.2 and i am trying to develop split view.
HELLO, I am working on XCODE 3.1.4 , my iphone have 3.1.2 os...But as

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.