-
Re: How to share a void in two files
NotMyName Jan 25, 2017 7:34 PM (in response to joshua_hii_zhen_hua)You appear to be using the wrong word, "void", to refer to something but you've chosen the wrong word. What did you mean to write?
-
Re: How to share a void in two files
joshua_hii_zhen_hua Jan 25, 2017 9:39 PM (in response to NotMyName)Thank you but "void" is not a wrong word. It's a code like "int" , "char", "return". The keyword "void" means, the method won't return anything. You can use "void" in this way:
int x;
-(void)addNumber{
x = x + 1;
}
And I want to ask you how to share the same "void" in different files. Can I use the keyword "extern"? Or is there other ways?
-
Re: How to share a void in two files
NotMyName Jan 26, 2017 2:27 PM (in response to joshua_hii_zhen_hua)Please have a nice day.
-
Re: How to share a void in two files
joshua_hii_zhen_hua Jan 26, 2017 3:51 PM (in response to NotMyName)What do you mean? Will you help me?
-
Re: How to share a void in two files
KMT Jan 27, 2017 7:59 AM (in response to joshua_hii_zhen_hua)Your use of 'void' in that example is understood, don't worry. What's not clear to me is what you're trying to share and why.
See this Apple document that may help answer your question - see operation tasks and concurrent queues as examples.:
Ken
-
Re: How to share a void in two files
joshua_hii_zhen_hua Jan 26, 2017 6:45 PM (in response to KMT)Thanks for your help but I don't see any 'extern' keyword or how to share the 'void' in different files. Can you tell me where is it? Thank you
-
Re: How to share a void in two files
KMT Jan 26, 2017 7:52 PM (in response to joshua_hii_zhen_hua)Quoting off the 'net...
(void) indicates the return type. '-' indicates that the method is an instance (vs. class) method. It requires an object to call it, and instance variables of the object are available to it inside its definition.
Which of those are you attempting to share/make available to other files? The return type? Not the method?
About keyword extern, see this SO thread:
Good luck.
-
Re: How to share a void in two files
joshua_hii_zhen_hua Jan 27, 2017 12:24 AM (in response to KMT)You answered my question. Thank you very much. They used 'extern' and 'void' in this way:
extern void xxx (void);
But I use in this way:
extern void xxx;
But no error occurs. Why?
-
Re: How to share a void in two files
eskimo Jan 27, 2017 1:46 AM (in response to joshua_hii_zhen_hua)extern void xxx (void);
Declares a function
xxx
that takes no parameters and returns nothing.extern void xxx;
Declares a variable
xxx
of typevoid
, which is weird and unhelpful but still legal C.Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: How to share a void in two files
joshua_hii_zhen_hua Jan 27, 2017 7:06 PM (in response to eskimo)Thanks for your explanation.
-
Re: How to share a void in two files
joshua_hii_zhen_hua Jan 27, 2017 7:31 PM (in response to eskimo)I have declared the 'void' in the .h file like this:
extern void xxx (void);
And Xcode says 'No visible @interface for 'view controller' declares the selector 'xxx' '. Why?
- (IBAction)usetoolSwitch:(id)sender { [self xxx]; //Error here }
Please help me. Thank you.
-
Re: How to share a void in two files
eskimo Jan 29, 2017 4:21 PM (in response to joshua_hii_zhen_hua)Because in your first snippet you’ve declared a function and in the second snippet you’re calling a method. These are different things.
I don’t think you’re going to be able to pick up Objective-C by asking questions here on DevForums. You need to find a tutorial to work through that explains the basics, like how to declare a method in one class and use it in another. I don’t have any good suggestions for such a tutorial (about 20 years ago I was in your shoes, learning Objective-C as a new language, but I fear all of those links are now broken :-) but perhaps someone else can make a suggestions.
Best of luck!
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: How to share a void in two files
ksigiscar@cmc Feb 2, 2017 4:15 AM (in response to eskimo)Best book for an introduction to Objective C
Objective-C Programming: The Big Nerd Ranch Guide
Book by Aaron Hillegass
For more advanced topics
Effective Objective-C 2.0: 52 Specific Ways to Improve Your IOS and OS X Programs
Book by Matt Galloway
-
Re: How to share a void in two files
eskimo Feb 2, 2017 3:14 PM (in response to ksigiscar@cmc)Best book for an introduction to Objective C …
For more advanced topics …
Thanks!
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardwarelet myEmail = "eskimo" + "1" + "@apple.com"
-
Re: How to share a void in two files
joshua_hii_zhen_hua Feb 19, 2017 4:37 AM (in response to eskimo)I found out the answer. I can call the method from another class with class method. But I have a question here, I want to compile like this in classA:
+(void)someMethod{ SKNode *image = [self childNodeWithImageNamed@"image"]; image.hidden = YES; }
I want to call it in classB:
[classB someMethod];
But SKNode is a instance variable and cannot compile in class method. Please help me. Thanks
-
Re: How to share a void in two files
PBK Feb 19, 2017 2:13 PM (in response to joshua_hii_zhen_hua)You will want to create an instance of this class so that the entire class will exist in memory along with all the variables that are global to that class. For examle, in the class that wants to call this method:
ClassA *anInstanceOfClassA=[[ClassA alloc] init];
Once you have created an instance of ClassA you can call a method in that instance of ClassA using:
[anInstanceOfClassA someMethod];
This is calling a "-(void)someMethod". You will want to include that in the ClasssA.h
ALL OF THIS and more!!! is explained in an introductory book - which you have read before. Read it again.
-
-
-
Re: How to share a void in two files
joshua_hii_zhen_hua Feb 18, 2017 5:30 AM (in response to ksigiscar@cmc)I've read that book before
-
Re: How to share a void in two files
PBK Feb 22, 2017 8:45 AM (in response to joshua_hii_zhen_hua)You now have 4 posts in a row all asking questions that are contained in that book that you read before. Read it again.
-
Re: How to share a void in two files
joshua_hii_zhen_hua Mar 13, 2017 1:52 AM (in response to PBK)I've read that book. It says the same as yours.
//GameViewController -(void)pause{ GameScene *gameScene = [[GameScene alloc] init]; [gameScene stop];//"Stop" is a method in GameScene } -(IBAction)pause:(id)sender{ [self pause]; } //GameScene -(void)stop{ ... // code to pause the game }
When I click the button, the game won't stop. Please help. Thanks
-
Re: How to share a void in two files
joshua_hii_zhen_hua Mar 24, 2017 8:28 PM (in response to joshua_hii_zhen_hua)Anyone please help? Thanks
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-