« first day (689 days earlier)      last day (1467 days later) » 
00:00 - 09:0009:00 - 00:00

12:37 AM
alright I'm sick of messing around with this. How do i send the instance of my class to another class?
 
an instance of one class to another, well are you using it as a parameter for a function or a property?
 
property
any clue?
 
what?
 
i'm trying to pass an instance of a class to another class so i can change it's properties
 
Do you know what is a property in objective c?
 
12:48 AM
@property BOOL showLeaderboard;
 
If you're trying to pass an instance of class A to class B, then have a property of Class A in class B. Then before you navigate to class B, set it and then navigate.
Yeah So do @property (nonatomic, strong) ClassA *a;
That will be in Class B
 
yes but i need to be able to pass the instance of class A first
 
well you could have a setter
 
otherwise i cannot access the property
 
so something like
- (void) setProperty: (ClassA*) a;
 
12:50 AM
doesn't dot-point notation set it easily?
 
You're passing instance of Class A only.
 
a setter gets called when you use dot-point
 
@Wingpad Property will create those accessor methods
 
@Gudiya wasn't sure if they needed a custom thing or not
but yeah they do
 
thing is i don't know how to pass the instance of Class A to the viewController
 
12:51 AM
Why not? How do you create the instance of other view controller?
 
I make an instance of MainMenu by presenting the scene, Then in the MainMenu i create button and clicking on the button create the relative scene. But when I press the back button on another scene it create's a new MainMenu instance, which obviously solving my issue. So either i need to get the first instance of MainMenu from the view to controller into the other classes or when i click the back button the new instance create gets sent to the view controller
 
Can you share screenshot of your scenes in storyboard?
 
it's a sprite kit game so it create's an SKView programmatically in the view controller
 
So You have Main Menu (lets say it's called as A). You present B from A. Now you want the reference of A in B?
 
lets say A is the viewController, then Main menu is B and MainGame is C
 
1:00 AM
Ok. Now you want what from what?
 
In C when the back button is pressed i either need to create a new instance of B and pass it to A
or i need to pass the instance of B which is in A To C
 
What do you mean instance of B which is in A? The flow is A -> B -> C, right? So when you're in B and you wanna go to C, you can pass the B's instance to C, right?
So In C, declare a property of type B
 
In A i create the instance of B then present the scene, and in B i create the instance of C then present the scene
 
Yes, so create a property of type B in class C.
Like this - @property (nonatomic, weak) ClassB *b;
Then, the place where you create instance of Class C, set that property, like this - instanceC.b = self;
 
then how do i set the properties value in C to be instance B
when instance b is created in A
 
1:07 AM
If instance of C is instanceC, then do instanceC.b = self
But when you're in B, self represents the current instance which is B only.
 
i need instance B to be sent to C, But instance A creates instance B in itself
 
What do you do with that instance B in A?
 
instance A is the view controller where i load the first scene instance B
 
Yes, so do what I said earlier.
 
then in instance B i load instance C when a button is pressed
 
1:12 AM
Create instance C in B, and set it's property to self
 
so in instance A how do i retrieve instance C's property
 
Why would you want C in A?
 
i need C in A so when i press the back button the class instance of B is changed in instance A so i can still load the game centre leader boards
because B is create in A and is set to a property, then i need to reset that property to the instance of B
 
Well, when you come back from C, C will be flushed from memory. So trying to get C in A makes no sense.
 
no i need C property of B to go to A
 
1:17 AM
Hi room.
Hi Laddu. Long time no see.
 
Hi Duncan.
Yeah, was gonna say the same thing :-)
 
I haven't been around.
I was on vacation for 2 weeks.
Then wasn't on much this week.
 
@Mutch95 What do you mean by C property of B?
I'm waiting for the next long weekend, Labor day.
 
in C we set a property to hold the instance of B don't we?
 
Yes
 
1:19 AM
so when the back button is pressed i need to send C's property holding the instance of B to A
 
Back button pressed in B, right?
Or you go to B directly from C?
 
no back button pressed in C Takes you to B
You can't get to A because it is in the view controller
so in B there is a BOOL property
 
Still that doesn't make sense. If you go A -> B -> and C. And now from C directly unwind to A, so when you reach A, both B and C are gone. So why would you want the B in A now?
 
in A i want to test whenever there is a touch is the property in B is set to yes
 
But B is already gone when you reach back to A, no?
 
1:22 AM
you can't reach A because either B or C will always be loaded
i just want to set the property in A to the value of C property
let me see if i can setup a paste bin
 
That still doesn't make sense to me. Okay, nevertheless - Have an property of C also in A and property of A in B. When you go to B, set it's A property. And in B when you create C to go to C, set the A's property to this C instance.
Hitting "back" to me means the current controller will be destroyed. So Trying to have a reference of the getting-to-be-destroyed controller is not good.
 
Here Is Instance A - pastebin.com/KgAnQk5D
 
Create a property of C in A.
 
Here Is Instance - B - pastebin.com/qMKzzNYJ
Here Is Instance - C - pastebin.com/SWGrksPu
so when the new instance of B is create In C i need to send that To the property in A so when the touch is click i can check whether the property in instance B is set to yes
Understand Now?
 
That's fine. You just want C in A, right? B already will have C when C is created. So if B has A, it can set A's property (which will be type C) to C.
So first create a property of type C in A.
Now B needs to have A so that it can set this property of A when it creates C.
So create a property of type A in B.
 
1:32 AM
i don't know to how send A as it is a view controller
 
send A to B you mean?
 
yes
but A is a view controller
Thats why i said only B or C will ever be seen
 
It should be as usual - @property(nonatomic, weak) ViewController *objA;
 
then in A ill set that property to self?
 
First put that in B.
 
1:36 AM
the property in B? alright
 
yes
 
it says to replace with UIViewController
iv'e add A class To B
 
Then @property (nonatomic, weak) MainGameScene *mainScene in A.
Then in A, after mainMenu.scaleMode = SKSceneScaleModeAspectFill; put mainMenu.objA = self;
 
yep then what
 
And in B before [self.view presentScene:self.mainGameScene transition:transition];, do self.objA. mainScene = self.mainGameScene;
And you should be done.
 
1:42 AM
I'm getting error messages because when i set mainScene in A its setting itself as a view controller
 
What is that line of code?
 
self.mainScene = self;
 
When did I specify that line of code?
 
aswell for the second part
hen in A, after mainMenu.scaleMode = SKSceneScaleModeAspectFill; put mainMenu.objA = self;
 
ok wait
Do you have @property(nonatomic, weak) ViewController *objA; in B?
 
1:46 AM
hold on i think i got it
i was mixing the properties around
no doesn't work still
 
Why it doesn't work? I told you everything that is needed.
Show what is not working.
 
because C still creates a new class instance of B
 
Let me ask @DuncanC and @nil to come in. Your view hierarchy is messed up, IMO.
 
Hello?
 
In view C shouldn't i set the new mainMenu to A?
 
user457812
1:54 AM
I did this for two hours last night, you're on your own.
 
i wish there was just a simple method i could follow that someone uses to send class instances to another class
 
user457812
There is. It's called a method.
 
the method won't send the instance class needed because, to call that method i need to crete an instance of that class. so that won't work.
 
user457812
I don't think anyone knows what you mean by that.
 
i need to create an instance of the class before i can call any methods and if i do that it's useless because it will return the instance of the class that was just created
if i could access the automatically create view controller i think i'd be find but i cannot do that can i.
 
2:37 AM
@Gudiya the properties are null
 
2:57 AM
@DuncanC hope you had a nice vacation :)
 
3:17 AM
the really shouldn't be so difficult should it?
 
hello there
here is my code. in my code in self.contactArray i want to compare a string with each contact.userId
if matches retrieve the result
can anyone help?
 
Write a StackOverflow question.
Mutch95: Nothing should be difficult.
 
i cannot pass and instance of a class to another class
 
Of course you can.
I have faith in you.
 
@EnricoSusatyo what are @protocols typically used for?
 
3:30 AM
You can use it for anything you want it to be.
But I recommend just following Apple's guide.
 
evaluate on that please?
oh ok
they're not going to fix the issue i am having anyway, doesn't matter
 
Evaluate on... ?
They are not fixing issues?
 
nothing doesn't matter
the apple documentation mentions nothing about passing instances of classes to and instance of a class
 
user457812
You allocated it somewhere, meaning somewhere some code has access to some thing and that thing can be passed around to other things.
 
user457812
You're just failing to see how your code is structured.
 
3:36 AM
but it's set in the viewcontroller
then it's also sent in main game scene, but then the ne in view controller need to be updated
 
user457812
I can't really help you when this is a conceptual problem.
 
user457812
Like, you need to get over your beliefs about what can and cannot be done.
 
so what can i do then?
 
You guys met each other?
 
user457812
We went over this for two hours last night, there's really nothing for me to add.
 
3:42 AM
i could return the new mainMenu scene to the view controller from mainGame but i cannot do that without making a new instance of the class mainGame. Maybe i could return MainGame and make a temp class then run the return method and set the new value to the view controller
 
user457812
Why would you have to make a new instance to return it?
 
because the class is defined somewhere else not in the view controller?
 
user457812
I think you have strange ideas about what a class and instance are.
 
or could i retrieve it from a property then run there method?
 
Hello
 
3:44 AM
well you create an instance of a class like so Class *obj = [Class new];
 
user457812
If you define a class with a method foo, if you pass an instance of that class to something else and then call foo, does that not work?
 
Hello to you too, Max.
 
Hows it going
 
user457812
And if it does work, why would you think it doesn't work in this case?
 
that's exactly what i want to do
 
3:45 AM
😕
 
user457812
And what's stopping you?
 
user457812
Aside from a mistaken belief that you can't do it.
 
That Emoji doesn't look happy Enrico
 
because i cannot retrieve the instance of the class
 
user457812
Why?
 
user457812
3:46 AM
If you couldn't retrieve an instance of the class, you'd never be able to interact with it upon allocation.
 
user457812
Clearly, you've got an instance of it.
 
user457812
Clearly, you can pass that instance to other things.
 
user457812
Clearly, you are forgetting this.
 
yes but the location of the instance is else where and i cannot retrieve it
 
user457812
Where is elsewhere?
 
user457812
3:48 AM
Did you not allocate whatever it is elsewhere?
 
elsewhere is another class
 
user457812
And if it's elsewhere, why do you suddenly not have access to it?
 
i only have access to it in the class?
 
user457812
Why?
 
user457812
I'm going to keep asking you why 'til you stop being wrong.
 
3:49 AM
because if i create another instance of that class the values will be reset to the initial values
 
user457812
Why do you need to create another instance? You already had one.
 
because that instance is declared in Class B and I need It in Class A
 
user457812
Why does that affect anything?
 
@Maximilian Yeah. Cold day, some weird stuff happened.
Why are we talking about foundation of OOP here? lol
 
because i cannot run a method without an instance of a class
 
user457812
3:51 AM
Except you have an instance.
 
.... if it's an instance method, of course you can't.
 
yes but the instance memory location isn't available to class A
it's only available in Class B
 
user457812
So how do you get it from B to A?
 
i have no clue
 
user457812
What is connecting B and A?
 
3:53 AM
#import
 
user457812
No.
 
user457812
Instances.
 
oh nothing
 
user457812
So is class A or class B unused entirely?
 
user457812
'Cause you can't have two things that are completely disconnected.
 
3:55 AM
Well class A has to be used because it's a view controller doesn't it and Class B would be currently init
so how are they connected though
 
user457812
Currently init?
 
initialised
 
user457812
How does that pertain to this?
 
user457812
What does "Class B would be currently init" mean?
 
user457812
I have an idea. Draw a graph of your entire application.
 
3:56 AM
i not know you're confusing me with all these why's
i have no clue how they are connected
 
user457812
Then draw a graph so you know.
 
no idea how to connect them
 
can someone please vote to open my questions?
 
user457812
Where does the application start?
 
and no idea how to access the instance From class B in Class A
 
user457812
3:57 AM
Find out where you application starts, and start drawing a graph.
 
the application starts in Class A which is the view controller
then Runs to MainMenu
Then MainGame
 
user457812
Ok, Mutch, when I say draw a graph, I mean literally draw the graph.
 
@IGotRoot You're asking us to reopen a node js question? lol
 
user457812
Go find yourself a piece of paper, get a pen or pencil, and draw a graph.
 
when the back button is pressed It creates a new main menu because i don't know where to retrieve from Class A and that's what my issue is
 
user457812
3:58 AM
I am completely serious about this. You are trying to connect things in your app and you apparently have no idea how anything's connected.
 
user457812
So start figuring out how stuff is connected.
 
user457812
You've got so many holes in what you know even about your own code that it's a miracle that you've gotten this far, so you need to figure out what it is you've even done.
 
drawn the graph
 
user457812
I don't believe you've managed to do that in such a short time when you've said you don't know how things are connected.
 
user457812
Read through your code, draw the graph based on the code, not based on "pressing this button goes back"
 
4:00 AM
View controller goes to main menu goes to maingame
 
user457812
And which of those is class B?
 
user457812
Since you're insistent upon not just using actual class names.
 
class B is main menu
 
user457812
So class B has the thing and on both sides of it, it has access to other instances.
 
so id actuallynee to retrieve the instance from class C
 
user457812
4:01 AM
Then why did you say it was in class B?
 
frustrated so I'm confusing myself
 
user457812
Then stop making up new names for the classes instead of just saying "MainMenu"
 
alright
 
user457812
If you want to know the easiest way to confuse yourself, it's to pick arbitrary names for stuff instead of just saying what it already is
 
this still doesn't fix my issue though
 
user457812
4:03 AM
At any rate, we've already established that all your instances are connected somehow.
 
user457812
So I don't see how this needs further discussion.
 
but how are they
 
user457812
You just said how.
 
so how do i access them then
 
You are a very patient man, nil.
 
user457812
4:09 AM
I'm leaving the how up to you since I can't really tell you anything beyond what I already have.
 
user457812
Basically, at this point, it's down to how you structure your code. You've apparently decided you cannot write code to fix this, so it's really going to stay that way 'til you realize that's not the case.
 
can you not just give me the basis code to fix this problem?
 
user457812
Nope.
 
why is that
 
user457812
Because I don't have your entire project and fixing your code isn't my job.
 
4:12 AM
well then tell me how you access instance of a class from other classes then?
 
user457812
By passing the instance where it needs to go.
 
user457812
We've been over this before.
 
i know
but i cannot pass something unless i create a new object
and creating a new object will give me the wrong data let alone affect the wrong scene
 
user457812
I've told you that's wrong multiple times. If you don't commit that to memory, then I can't do much about that.
 
....
Is this your first programming language/framework, Mutch?
 
4:15 AM
yes...
 
user457812
Plus this is starting to remind me of talking to republicans who repeat talking points even though they're wrong, so I'm out.
 
OOP is about a step above traditional programming. Might want to get that nailed down first.
 
i've already bought everything
so i can't just quit\
 
What do you mean you bought everything?
 
i don't see why you can't just show me the code that pass an instance of a class
developer program ($99), mac ($3500), Books
 
user457812
4:17 AM
Because passing an instance of something is literally just calling a method and passing the instance using that.
 
user457812
A Mac doesn't cost $3500 unless you bought a Mac Pro for some reason.
 
imac
but how do i call the method without an object
 
My Mac cost me $1,800 shrug
You can't if it's an instance method.
 
user457812
By having an instance
 
Why are you repeating the same question that's been answered? lol
 
4:19 AM
so i have to create a class method
because to me it hasn't been answered
 
lol, not necessarily.
 
user457812
You are literally the most frustrating person ever because you act like your code cannot change and you can't allocate instances and you can't pass instances as arguments to methods.
 
i dont understand how to get the instance if i need to have the instance to call the method
 
user457812
Like, deeply frustrating, because this is so far beyond my level of understanding when it comes to beginner trouble
 
LOLLL
 
4:21 AM
if you could literally just post the code which will pass the instance class to another instance class that'd help
 
user457812
So I'm done before I start getting overly sarcastic, because I'm pretty sure we're up to three hours I've spent on this.
 
user457812
What code? We don't have your code. We cannot write generic code for this.
 
i don't want generic code
 
user457812
This is not a generic problem, this is a your-code-needs-a-specific-thing problem.
 
i just want an example
 
user457812
4:22 AM
Only you can fix this.
 
user457812
And in order to fix this you need to stop getting it wrong.
 
user457812
And in this case, I think you need to just abandon this project, start your learning over from scratch, and suck it up.
 
There is a website that has full of examples, it's called GitHub.com.
 
and i can't get it right if i don't know the answer
 
user457812
Start over from scratch. Learn Objective-C properly. Learn programming fundamentals. Learn how MVC works. Learn all this stuff you already need to know that you don't.
 
user457812
4:24 AM
There are too many holes in your knowledge, there's no patching it over, you can't continue like this — start over.
 
user457812
It's going to suck because you've spent however much in time and money on this, but you skipped too many things in the process.
 
give me the line of code that will call the returning method
 
user457812
No.
 
user457812
There is no line of code.
 
[obj someReturnMethod];
 
user457812
4:25 AM
If you want a line of code, this is what it'll look like [something doSomething];
 
I seriously don't understand what line of code that you want lol.
 
is that it?
 
user457812
I don't know?
 
alright and something where did something come from?
 
user457812
This is a problem specific to your code. There's no line of code I could show you that would tell you anything.
 
user457812
4:26 AM
I don't know. You figure that out.
 
user457812
goes back to watching someone play Oregon Trail 2
 
something is the instance! and i cannot get the instance without creating one
 
Hahahahaha
Oh man this is a very difficult problem.
 
careful this image is newt safe for work 31.media.tumblr.com/1a0f4642c95efb977df56cb983ed34c9/…
 
user457812
@EnricoSusatyo Only in so far as he's the problem and not the code.
 
4:28 AM
LOL, yeah.
 
so you're saying if you compile it, it'll compile differently..
this is stupid. you're just playing games with me.
 
user457812
In a few years, when you're comfortable programming and reasonably competent, you're going to look back on this and try to strangle your past self.
 
user457812
Trust me.
 
why do you maker it sound so easy, when its difficult.
 
He's not saying if he compiles it, it'll compile differently. He's saying that you just wouldn't listen what we're telling you.
You ask the same question over and over again. I can see that even from half sitting in this room for 40 minutes.
 
user457812
4:36 AM
It's easy because I've been doing this crap for something like 8-10 years.
 
user457812
Beginning programming is hard as hell and I cannot remember what it's like, much less the thought process of a beginner programmer
 
so you're saying literally all i have to do is return the value to the view controller
 
See? You are doing it again.
 
so whats the answer then...
 
You just sprout an unrelated question out of nowhere and we have no idea what the context is.
 
user457812
4:38 AM
Return or pass. I don't know why it has to be a return.
 
user457812
I mean, admittedly, if you used properties instead of just tons of instance variables, this would probably be a non-issue entirely.
 
it still confuses the hell out of me on how you call your methods if you don't even create the object in the same class
 
That question in itself confuses me.
 
that's why I'm confused
because he says i can [something doSomething];
 
He is right.
 
4:52 AM
without even having to create a new instance
 
If doSomething is a class method, yes.
 
but still even if it was a class method it's not going to give me the value from the instance of the class something
 
Now I'm confused, and I just got here.
raywenderlich.com. Tutorials. Do...all of them, then come back. :D
 
all i want to know is how code would look to pass an instance of a class to another instance of a class
some of them are good
 
I wouldn't strongly endorse raywenderlich.
But yeah you need to re learn a lot of stuff.
 
5:05 AM
why can none just show an example code.
 
I know of no better single source of iOS tutorials on the web. Sure, some of the tutorial writers have a better grasp of CS fundamentals than others, but overall, it's my goto.
 
Because we don't know what you want...
There are tons of example codes in github, stackoverflow, etc.
 
all i want to know is how code would look to pass an instance of a class to another instance of a class
 
xianritchie: Well, I agree. I also think the coding style in that site can be improved.
 
You want to pass an instance of a class to another instance of the same class?
 
5:06 AM
thisInstance.someProperty = anotherInstance.someOtherProperty;
 
no an instance of another class
 
Or [thisInstance setSomeProperty:[anotherInstance someOtherProperty]];
You see how difficult it is for me to answer?
 
The problem is, it matters what you want it to do.
 
yes but getting anotherInstance how would i get that
 
Does anyone remember what that auto layout github library that matt or someone else mentioned a few times?
Masonry, got it.
 
5:09 AM
Lets say you have one class, Wheel, and another class, Car. You could make a Wheel *wheel property in the Car class, and just set it like:

Wheel *myWheel = [Wheel new];
Car *myCar = [Car new];
myCar.wheel = myWheel;
 
Excellent example. Except he may be confused because you are using new instead of alloc init
 
no i know what new is geez
 
But if you want to just do something with it, and not set a property, then you need to define a method in the Car class that TAKES a Wheel.

-(void)printWheel:(Wheel *)wheel {
NSLog(@"%@", wheel);
}

And then invoke it like:

[myCar printWheel:myWheel];
That's it. One instance either assigns itself as a property of another class, or is handled by a method of another class.
 
finally some code thank you @xianritchie
 
Honestly, your questions weren't all that clear. I realize you're new, but it helps to take some time to ensure you're asking with clarity
i have the dubious misfortune of having spent a decade doing technical customer service, so I'm fluent in half-asked questions. :P
 
5:14 AM
sorry
 
It's okay.
I only say it for your own good. This is a place to share, learn, grow, but it doesn't help you to put yourself on the outside because people are frustrated with you. :)
Also, one more piece: class vs instance methods - not every instance of a class needs to know everything or do everything. Sometimes, you just need the class to know about it. In that case, you'll see that the code would be written like this in examples:

+(void)printWheel: (Wheel *)wheel {
NSLog(@"%@", wheel);
}

and would be invoked by the class name itself:

[Car printWheel:myWheel];
Because there is no relevant code in my examples, this doesn't mean anything here, but it's important if you haven't encountered the syntax a lot, because I've copied from examples and realized later that my frustration came with trying to call an instance method that was a class method.
 
user457812
6:05 AM
I'm going to be there's a retain cycle in there somewhere
 
6:15 AM
In where?
 
user457812
6:27 AM
*bet
 
user457812
Also, in Mutch's code. Somewhere.
 
7:40 AM
are you doubting me :(
 
user457812
8:30 AM
Hm, not sure what happens if I declare the same operator twice in different files in Swift.
 
still can't send anything to the view controller,
 
8:44 AM
ViewController *vc = self.view.window.rootViewController;
[vc setMainMenu:mainMenu];
reallY!!!! THIS IS ALL I NEEDED
WOW.
only thing is it's getting a yellow error because its an instance of viewController and not UIViewController
 
user457812
Because there's no guarantee that the window's rootViewController will be your view controller at all times, since you might end up making another view controller root later.
 
if i don't make one programmatically it's alright to leave that error or no?
any bypass?
 
00:00 - 09:0009:00 - 00:00

« first day (689 days earlier)      last day (1467 days later) »