Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dotnet/Templates/Microsoft.iOS.Templates/ios/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
using iOSApp1;

#if DEBUG
Copy link
Copy Markdown
Member

@rolfbjarne rolfbjarne Jan 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip updating templates if:

  • We have a private check_for... field we set when we generate our unmanaged main function (or somehow set this value during build time) - and set it to true for debug builds and false otherwise.
  • In the linker detect if the public CheckFor... setter has been preserved. If not, we can treat the getter as a constant value (because we'll know what we set the private field to).
  • Then we'll run the dead code eliminator in the linker and remove the corresponding code paths.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removing the fields (or properties) is easy (many ways) at least if they are not set from the .cctor. But the savings(of two fields) are very minimal since the rest of the logic is already removed. It's mostly a nice side effect :-)

However this keeps the features (and logic) into the magic/unseen land, which is bad for feature discovery. Even when documented a feature is only useful if you know about it (and for .net it won't be the old mtouch additional arguments to override them). Having the templates makes them obvious, at least more than finding the new (was it added) correct msbuild syntax.

// Enable runtime checks to ensure some types are only used from the main (UI) thread
UIApplication.CheckForIllegalCrossThreadCalls = true;
// Enable runtime checks to ensure ObjC delegates and events (using their own delegates) are not mixed
UIApplication.CheckForEventAndDelegateMismatches = true;
#endif

// This is the main entry point of the application.
// If you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
Expand Down
6 changes: 6 additions & 0 deletions src/AppKit/NSApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@

namespace AppKit {
public partial class NSApplication : NSResponder {

#if NET
public static bool CheckForIllegalCrossThreadCalls { get; set; }
public static bool CheckForEventAndDelegateMismatches { get; set; }
#else
public static bool CheckForIllegalCrossThreadCalls = true;
public static bool CheckForEventAndDelegateMismatches = true;
#endif

#if !(XAMCORE_4_0 && NET)
#if NET
Expand Down
5 changes: 5 additions & 0 deletions src/UIKit/UIApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ partial class UIApplication
#endif
{
static Thread? mainThread;
#if NET
public static bool CheckForIllegalCrossThreadCalls { get; set; }
public static bool CheckForEventAndDelegateMismatches { get; set; }
#else
public static bool CheckForIllegalCrossThreadCalls = true;
public static bool CheckForEventAndDelegateMismatches = true;
#endif

#if !WATCH
// We link with __Internal here so that this function is interposable from third-party native libraries.
Expand Down