Date   

Re: Properties being set to nil?

Dave
 

Looking at the log (and reformatting it a bit):

initWithCoder: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>
viewDidLoad: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>

initWithCoder: <LTWMacGameViewController: 0x60000350d4a0>
awakeFromNib: <LTWMacGameViewController: 0x60000350d4a0>
setGameCommandDelegate: <LTWMacGameViewController: 0x60000350d4a0>

viewWillAppear: <LTWMacGameViewController: 0x600003514370>
viewDidAppear: <LTWMacGameViewController: 0x600003514370>

catchBug: <LTWMacGameViewController: 0x60000350d4a0>

So it looks like the 0x600003514370 instance is the good one and 0x60000350d4a0 the imposter!

On 16 Jan 2020, at 19:38, Dave <dave@...> wrote:

Hi Jon,

Can you just set an outlet to point to the instance loaded from your storyboard and leave it from that (that's what you should be doing unless you need multiple instances of LTWGameViewController in your app).

I’m not sure what you mean? Do you mean an outlet to the LTWGameViewController in the StartupWindowController?

Here’s what I am doing:

In AppDelegate::applicationDidFinishLaunching

myStoryboard = [NSStoryboard storyboardWithName:kLTWStartupStoryboardName bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:kLTWStartupWindowControllerID];
if (myGameWindowController == nil)
{
return;
}
self.pStartupWindowController = myGameWindowController;

[myGameWindowController showWindow:nil];

----------------------

In the StartupViewController:


-(void) viewDidAppear
{
NSStoryboard* myStoryboard;
NSWindowController* myGameWindowController;
LTWMacGameViewController* myGameViewController;
NSString* myGameID;
LTWSudokuAppManager* myAppManager;

//**
//** Instantiate the Game Window Controller
//**
myStoryboard = [NSStoryboard storyboardWithName:kLTWGameStoryboardName bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainWindowControllerID];
if (myGameWindowController == nil)
{
return;
}

//**
//** Instantiate the Game View Controller
//**
myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}

//**
//** Create a New Game  
//**
myGameID = [self.pSingletonManager.pSudokuAppManager newGameWithReportDelegate:myGameViewController];

//**
//** Set the Game View Controller Delegates
//**
myAppManager = self.pSingletonManager.pSudokuAppManager;
[myGameViewController setGameControlDelegate:[myAppManager getGameControlDelegate]];
[myGameViewController setGameCommandDelegate:[myAppManager getGameCommandDelegate]];

self.pGameViewController = myGameViewController;
self.pGameWindowController = myGameWindowController;
[self.pGameWindowController showWindow:nil];

//**
//** Close the Startup Window
//**
[self.view.window close];


————————————————————

When I run I get this in the log:

initWithCoder: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>
viewDidLoad: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>
initWithCoder: <LTWMacGameViewController: 0x60000350d4a0>
awakeFromNib: <LTWMacGameViewController: 0x60000350d4a0>
setGameCommandDelegate: <LTWMacGameViewController: 0x60000350d4a0>
viewWillAppear: <LTWMacGameViewController: 0x600003514370>
viewDidAppear: <LTWMacGameViewController: 0x600003514370>
catchBug: <LTWMacGameViewController: 0x60000350d4a0>

catchBug is a method that gets called after a delay after the delegate is set.

So it does look like there are 2 instances!


Cheers
Dave



On 16 Jan 2020, at 19:06, Jon Gotow <gotow@...> wrote:

On Jan 16, 2020, at 10:48 AM, Dave <dave@...> wrote:

Yes, LTWGameViewController is a subclass of NSViewController and I set the Class in the Storyboard. 

When I set a breakpoint in the Set Delegate method it shows the property set ok. Later on it responds to an IBAction and its set to nil. It certainly looks like there are 2 objects! Is this a bug? Is there a work-around?

The fact that you've got two instances of your LTWGameViewController certainly sounds like a bug. It's difficult to tell without looking at your whole project, but my guess is that you've got one instance loaded from the storyboard, and then you're creating a second one programmatically later. Can you just set an outlet to point to the instance loaded from your storyboard and leave it from that (that's what you should be doing unless you need multiple instances of LTWGameViewController in your app).

- Jon







Re: Properties being set to nil?

Dave
 

Hi Jon,

Can you just set an outlet to point to the instance loaded from your storyboard and leave it from that (that's what you should be doing unless you need multiple instances of LTWGameViewController in your app).

I’m not sure what you mean? Do you mean an outlet to the LTWGameViewController in the StartupWindowController?

Here’s what I am doing:

In AppDelegate::applicationDidFinishLaunching

myStoryboard = [NSStoryboard storyboardWithName:kLTWStartupStoryboardName bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:kLTWStartupWindowControllerID];
if (myGameWindowController == nil)
{
return;
}
self.pStartupWindowController = myGameWindowController;

[myGameWindowController showWindow:nil];

----------------------

In the StartupViewController:


-(void) viewDidAppear
{
NSStoryboard* myStoryboard;
NSWindowController* myGameWindowController;
LTWMacGameViewController* myGameViewController;
NSString* myGameID;
LTWSudokuAppManager* myAppManager;

//**
//** Instantiate the Game Window Controller
//**
myStoryboard = [NSStoryboard storyboardWithName:kLTWGameStoryboardName bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainWindowControllerID];
if (myGameWindowController == nil)
{
return;
}

//**
//** Instantiate the Game View Controller
//**
myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}

//**
//** Create a New Game  
//**
myGameID = [self.pSingletonManager.pSudokuAppManager newGameWithReportDelegate:myGameViewController];

//**
//** Set the Game View Controller Delegates
//**
myAppManager = self.pSingletonManager.pSudokuAppManager;
[myGameViewController setGameControlDelegate:[myAppManager getGameControlDelegate]];
[myGameViewController setGameCommandDelegate:[myAppManager getGameCommandDelegate]];

self.pGameViewController = myGameViewController;
self.pGameWindowController = myGameWindowController;
[self.pGameWindowController showWindow:nil];

//**
//** Close the Startup Window
//**
[self.view.window close];


————————————————————

When I run I get this in the log:

initWithCoder: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>
viewDidLoad: <LTWMacGameViewController: 0x600003514370>
awakeFromNib: <LTWMacGameViewController: 0x600003514370>
initWithCoder: <LTWMacGameViewController: 0x60000350d4a0>
awakeFromNib: <LTWMacGameViewController: 0x60000350d4a0>
setGameCommandDelegate: <LTWMacGameViewController: 0x60000350d4a0>
viewWillAppear: <LTWMacGameViewController: 0x600003514370>
viewDidAppear: <LTWMacGameViewController: 0x600003514370>
catchBug: <LTWMacGameViewController: 0x60000350d4a0>

catchBug is a method that gets called after a delay after the delegate is set.

So it does look like there are 2 instances!


Cheers
Dave



On 16 Jan 2020, at 19:06, Jon Gotow <gotow@...> wrote:

On Jan 16, 2020, at 10:48 AM, Dave <dave@...> wrote:

Yes, LTWGameViewController is a subclass of NSViewController and I set the Class in the Storyboard.

When I set a breakpoint in the Set Delegate method it shows the property set ok. Later on it responds to an IBAction and its set to nil. It certainly looks like there are 2 objects! Is this a bug? Is there a work-around?

The fact that you've got two instances of your LTWGameViewController certainly sounds like a bug. It's difficult to tell without looking at your whole project, but my guess is that you've got one instance loaded from the storyboard, and then you're creating a second one programmatically later. Can you just set an outlet to point to the instance loaded from your storyboard and leave it from that (that's what you should be doing unless you need multiple instances of LTWGameViewController in your app).

- Jon






Re: Properties being set to nil?

Jon Gotow
 

On Jan 16, 2020, at 10:48 AM, Dave <dave@looktowindward.com> wrote:

Yes, LTWGameViewController is a subclass of NSViewController and I set the Class in the Storyboard.

When I set a breakpoint in the Set Delegate method it shows the property set ok. Later on it responds to an IBAction and its set to nil. It certainly looks like there are 2 objects! Is this a bug? Is there a work-around?
The fact that you've got two instances of your LTWGameViewController certainly sounds like a bug. It's difficult to tell without looking at your whole project, but my guess is that you've got one instance loaded from the storyboard, and then you're creating a second one programmatically later. Can you just set an outlet to point to the instance loaded from your storyboard and leave it from that (that's what you should be doing unless you need multiple instances of LTWGameViewController in your app).

- Jon


Re: Properties being set to nil?

Dave
 

Hi Sandor,

Yes, LTWGameViewController is a subclass of NSViewController and I set the Class in the Storyboard.

When I set a breakpoint in the Set Delegate method it shows the property set ok. Later on it responds to an IBAction and its set to nil. It certainly looks like there are 2 objects! Is this a bug? Is there a work-around?

Thanks a lot for your help.
Dave

On 16 Jan 2020, at 18:36, Sandor Szatmari <admin.szatmari.net@gmail.com> wrote:

I’ve seen this happen if the view controller is instantiated in code and in the NIB (not sure about storyboards)

It gets hooked up correctly one time and things are nil in the other case. Are you subclassing NSViewController and setting it to the class of a view controller in your storyboard? If so, and your also instantiating the view controller in code you’ll see two initializations of the object. One will be good and the other may or may not.

Sandor

On Jan 16, 2020, at 12:20, Dave <dave@looktowindward.com> wrote:


Re: Properties being set to nil?

Sandor Szatmari
 

I’ve seen this happen if the view controller is instantiated in code and in the NIB (not sure about storyboards)

It gets hooked up correctly one time and things are nil in the other case. Are you subclassing NSViewController and setting it to the class of a view controller in your storyboard? If so, and your also instantiating the view controller in code you’ll see two initializations of the object. One will be good and the other may or may not.

Sandor

On Jan 16, 2020, at 12:20, Dave <dave@looktowindward.com> wrote:


Re: Properties being set to nil?

Dave
 

Hi,

This is the only place the View Controller is instantiated. One thing I’ve notice is that if I set a breakpoint in ViewDidLoad and print self:

< LTWMacGameViewController: 0x600003500840>

and then again in setGameControlDelegate

<LTWMacGameViewController: 0x6000035082c0>

The addresses are different, so it looks like the View Controller returned by instantiateControllerWithIdentifier is different to the one actually instantiated?

Cheers
Dave


On 16 Jan 2020, at 18:00, Jon Gotow <gotow@...> wrote:

Any chance you're reloading your view controller (when starting a new game or whatever) and not subsequently setting the delegates again?

- Jon


On Jan 16, 2020, at 9:55 AM, Dave <dave@...> wrote:

Hi All,

I have a View Controller that is Instantiated in code from a storyboard file:

myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}

I then set some delegates:

[myGameViewController setGameControlDelegate:[self getGameControlDelegate]];
[myGameViewController setGameCommandDelegate:[self getGameCommandDelegate]];

These methods just store the delegate in Strong properties, I’ve checked and they are set ok.

However, I put a break point in viewDidLoad: and look at the properties again they have been set to nil!

I’ve checked and the properties in question are only set once in the appropriate setDelagateMethod.

Is there some magic going on? Is it legal to do this?

Thanks in advance for any help?

Dave












Re: Properties being set to nil?

Jon Gotow
 

Any chance you're reloading your view controller (when starting a new game or whatever) and not subsequently setting the delegates again?

- Jon

On Jan 16, 2020, at 9:55 AM, Dave <dave@looktowindward.com> wrote:

Hi All,

I have a View Controller that is Instantiated in code from a storyboard file:

myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}

I then set some delegates:

[myGameViewController setGameControlDelegate:[self getGameControlDelegate]];
[myGameViewController setGameCommandDelegate:[self getGameCommandDelegate]];

These methods just store the delegate in Strong properties, I’ve checked and they are set ok.

However, I put a break point in viewDidLoad: and look at the properties again they have been set to nil!

I’ve checked and the properties in question are only set once in the appropriate setDelagateMethod.

Is there some magic going on? Is it legal to do this?

Thanks in advance for any help?

Dave






Properties being set to nil?

Dave
 

Hi All,

I have a View Controller that is Instantiated in code from a storyboard file:

myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}

I then set some delegates:

[myGameViewController setGameControlDelegate:[self getGameControlDelegate]];
[myGameViewController setGameCommandDelegate:[self getGameCommandDelegate]];

These methods just store the delegate in Strong properties, I’ve checked and they are set ok.

However, I put a break point in viewDidLoad: and look at the properties again they have been set to nil!

I’ve checked and the properties in question are only set once in the appropriate setDelagateMethod.

Is there some magic going on? Is it legal to do this?

Thanks in advance for any help?

Dave


Re: Header Files

Peter Hudson
 

Great !
Peter

On 16 Jan 2020, at 16:23, Sandor Szatmari <admin.szatmari.net@gmail.com> wrote:

I usually type out the symbol I’m looking for and then right click and select jump to definition.

Sandor

On Jan 16, 2020, at 10:37, Peter Hudson via Groups.Io <Peter.hudson=me.com@groups.io> wrote:


Re: Header Files

Sandor Szatmari
 

I usually type out the symbol I’m looking for and then right click and select jump to definition.

Sandor

On Jan 16, 2020, at 10:37, Peter Hudson via Groups.Io <Peter.hudson=me.com@groups.io> wrote:


Header Files

Peter Hudson
 

I’m trying to find which files numerical min max types are defined in.

Specifically, NSUInteger and its associated types.

I havent had to look any up for so long, I’ve completely forgotten where they are - and how to open them in Xcode.

Any help welcome !

Peter


Re: When does AppDelegate:applicationDidFinishLaunching get called?

Sandor Szatmari
 

Excellent! Glad that was the trick!

On Jan 15, 2020, at 08:13, Dave <dave@looktowindward.com> wrote:

Hi,

Ahhh, you mean, awakeFromNib in the AppDelegate not the window/view controller. I think I was trying to avoid tying the initialisation to a NIB (in case I ever created it programmatically), but I guess in the case of the NSApplication object it will always be from a NIB so it’s safe.

Thanks a lot
Dave


On 15 Jan 2020, at 13:49, Sandor Szatmari <admin.szatmari.net@gmail.com> wrote:

I see different behaviour. Here’s a test app. No matter what I do, -awakeFromNib is always called first. I tried it both in the AppDelegate, and in the ViewController subclass.

Cheers,
Sandor


On Jan 15, 2020, at 05:51, Dave <dave@looktowindward.com> wrote:
Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave






<tester.zip>



Re: When does AppDelegate:applicationDidFinishLaunching get called?

Dave
 

Hi,

Ahhh, you mean, awakeFromNib in the AppDelegate not the window/view controller. I think I was trying to avoid tying the initialisation to a NIB (in case I ever created it programmatically), but I guess in the case of the NSApplication object it will always be from a NIB so it’s safe.

Thanks a lot
Dave

On 15 Jan 2020, at 13:49, Sandor Szatmari <admin.szatmari.net@gmail.com> wrote:

I see different behaviour. Here’s a test app. No matter what I do, -awakeFromNib is always called first. I tried it both in the AppDelegate, and in the ViewController subclass.

Cheers,
Sandor


On Jan 15, 2020, at 05:51, Dave <dave@looktowindward.com> wrote:

Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave






<tester.zip>


Re: When does AppDelegate:applicationDidFinishLaunching get called?

Sandor Szatmari
 

There’s a test app attached to demonstrate…

Sandor

On Jan 15, 2020, at 07:49, Sandor Szatmari via Groups.Io <admin.szatmari.net=gmail.com@groups.io> wrote:

I see different behaviour. Here’s a test app. No matter what I do, -awakeFromNib is always called first. I tried it both in the AppDelegate, and in the ViewController subclass.

Cheers,
Sandor


On Jan 15, 2020, at 05:51, Dave <dave@looktowindward.com> wrote:

Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave






<tester.zip>


Re: When does AppDelegate:applicationDidFinishLaunching get called?

Sandor Szatmari
 

I see different behaviour. Here’s a test app. No matter what I do, -awakeFromNib is always called first. I tried it both in the AppDelegate, and in the ViewController subclass.

Cheers,
Sandor

On Jan 15, 2020, at 05:51, Dave <dave@looktowindward.com> wrote:

Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave





Re: When does AppDelegate:applicationDidFinishLaunching get called?

Dave
 

Hi,

A little more on this.

If I uncheck “Is Initial Controller”, then applicationDidFinishLaunching gets calls as expected.

So I put the code back to instantiate it manually and all works as expected.

All the Best
Dave


Re: When does AppDelegate:applicationDidFinishLaunching get called?

Dave
 

Hi,

This is a Mac project but I will be doing an IOS version too.

I’ve tried applicationWillFinishLaunching and applicationDidFinishLaunching, but the View Controller gets control before either are called.

This is a Single Window based App.

The difference is that before I was manually instantiating the View Controller in applicationDidFinishLaunching (after initialising the App), now its being instantiated automatically by the OS.

Seems a bit weird to be honest, the fact that the Window has displayed means that the App

What dictates whether an App has launched? I’m guessing that the automatic loading is considered part of the Launch process, which would make sense given the naming of the methods.

Maybe there should be a “applicationDidBeginLauching”.

If there really isn’t a safe place to perform this type of initialisation then I guess I could always go back to manually instantiating the Window/View Controller…..

All the Best
Dave


Is this a document-based app or a single-window type app?

In my single-window apps, AppDelegate:applicationDidFinishLaunching is called first, and instantiates and displays the main window, so the window’s init and awakeFromNib methods are called before AppDelegate:applicationDidFinishLaunching ends.

In my document-based app, the DocumentWIndowController:windowDidLoad (and presumably viewDidAppear) are called before the AppDelegate:applicationDidFinishLaunching.

Jim Crate


Re: When does AppDelegate:applicationDidFinishLaunching get called?

Jim
 

On Jan 14, 2020, at 10:59 AM, Dave <dave@looktowindward.com> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?
Is this a document-based app or a single-window type app?

In my single-window apps, AppDelegate:applicationDidFinishLaunching is called first, and instantiates and displays the main window, so the window’s init and awakeFromNib methods are called before AppDelegate:applicationDidFinishLaunching ends.

In my document-based app, the DocumentWIndowController:windowDidLoad (and presumably viewDidAppear) are called before the AppDelegate:applicationDidFinishLaunching.

Jim Crate


Re: When does AppDelegate:applicationDidFinishLaunching get called?

Sandor Szatmari
 

On Jan 14, 2020, at 11:47, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:

You can also look at other methods in the AppDelegate, such as init,
If you’re going to look at -init, if it’s an object coming from a NIB then look at overriding -initWithCoder:
applicationWillFinishLaunchingWithOptions and so on.

Just look at the header. They are easy to try.
On Jan 14, 2020, at 9:59 AM, Dave <dave@looktowindward.com> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave






Re: When does AppDelegate:applicationDidFinishLaunching get called?

Jonathan Prescott
 

Since you referenced a Window, I’m assuming MacOS application, not iOS. Probably the same, but not sure since I don’t program for iOS.

According to the documentation, applicationDidFinishLaunching is called by NSApplication just before entering into the application event loop. You could try applicationWillFinishLaunching, which is called just after the application object is initialized, which should be before any controllers are created, if that is appropriate. You could also override the init() method (Swift or Objective-C) if that makes sense.

Jonathan

On Jan 14, 2020, at 10:59 AM, Dave <dave@looktowindward.com> wrote:

Mac Project.
MacOS 10.14.6

Hi All,

I have some code that needs to be initialized before any Window/View are displayed. The App was working ok, but it looks like something has changed?

I have a call to initialise AppDelegate:applicationDidFinishLaunching BUT, the Initial Window/View Controller viewDidAppear method is being called before applicationDidFinishLaunching. Is this correct behaviour and if so where is the best place to initialise things?

Thanks a lot
All the Best
Dave



261 - 280 of 1426