Skip to content

Commit

Permalink
Don't warn about Foundation.NSString (#4)
Browse files Browse the repository at this point in the history
Examples like this are fine:

	class MyCustomCell : UITableViewCell
	{
		static readonly NSString MyCellId = new NSString("MyCustomCell");
	}
  • Loading branch information
jonathanpeppers committed Aug 15, 2023
1 parent ea25f03 commit f409d32
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
13 changes: 13 additions & 0 deletions MemoryAnalyzers/MemoryAnalyzers.Test/MemoryAnalyzersUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ class MyViewSubclass : UIView
await VerifyCS.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task NSStringFieldIsOK()
{
var test = """
class MyCustomCell : UITableViewCell
{
static readonly NSString MyCellId = new NSString("MyCustomCell");
}
""";

await VerifyCS.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task UIView_CAShapeLayer()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public UnconditionalSuppressMessageAttribute(string category, string checkId)
}
""");

// Foundation.NSObject
// Foundation
testState.Sources.Add("""
namespace Foundation;

Expand All @@ -120,33 +120,32 @@ public RegisterAttribute(string name, bool isWrapper)

[Register("NSObject", isWrapper: true)]
class NSObject { }

[Register("NSString", isWrapper: true)]
class NSString : NSObject
{
public NSString(string text) { }
}
""");

// UIKit.UIView
// UIKit
testState.Sources.Add("""
namespace UIKit;

[Register("UIView", isWrapper: true)]
class UIView : NSObject { }
""");

// UIKit.UIColor
testState.Sources.Add("""
namespace UIKit;

[Register("UIColor", true)]
class UIColor : NSObject { }
""");

// UIKit.UIImage
testState.Sources.Add("""
namespace UIKit;

[Register("UIImage", true)]
class UIImage : NSObject { }

[Register("UITableViewCell", true)]
class UITableViewCell : UIView { }
""");

// CoreAnimation.CALayer
// CoreAnimation
testState.Sources.Add("""
namespace CoreAnimation;

Expand Down
2 changes: 2 additions & 0 deletions MemoryAnalyzers/MemoryAnalyzers/MemoryAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ static readonly HashSet<(string Namespace, string Name)> GenerallySafe = new()
{ ("UIKit", "UIColor") },
// UIImage is fine
{ ("UIKit", "UIImage") },
// NSString is fine
{ ("Foundation", "NSString") },
};

/// <summary>
Expand Down

0 comments on commit f409d32

Please sign in to comment.