From 89ce6055a61ecbc958c582d4ea57a4277ca60fd2 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 17 Nov 2024 14:41:41 -0800 Subject: [PATCH] iOS,macOS: Fix string constant declarations (flutter/engine#56661) A couple string constants had been incorrectly declared `const NSString*` rather than `NSString* const`. The former is a pointer to an immutable string, but (a) the pointer can be reassigned and (b) the default NSString implementation is immutable. The latter is an immutable pointer to a string, which is what we want, since we don't want developers reassinging our constants to other values. Also updates an identifier name to pass lint rules. No changes to tests since this is "tested" by the compiler. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../darwin/common/framework/Source/FlutterNSBundleUtils.h | 2 +- .../darwin/common/framework/Source/FlutterNSBundleUtils.mm | 5 ++++- .../darwin/ios/framework/Source/FlutterPlatformPlugin.mm | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h b/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h index 93dfc77989..e9b745cfdb 100644 --- a/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h +++ b/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN -extern const NSString* kDefaultAssetPath; +extern NSString* const kDefaultAssetPath; // Finds a bundle with the named `flutterFrameworkBundleID` within `searchURL`. // diff --git a/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm b/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm index c96b1a9af1..369e3ce263 100644 --- a/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm +++ b/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm @@ -2,13 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#import "flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h" + #include #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" FLUTTER_ASSERT_ARC -const NSString* kDefaultAssetPath = @"Frameworks/App.framework/flutter_assets"; +NSString* const kDefaultAssetPath = @"Frameworks/App.framework/flutter_assets"; + static NSString* GetFlutterAssetsPathFromBundle(NSBundle* bundle, NSString* relativeAssetsPath); NSBundle* FLTFrameworkBundleInternal(NSString* flutterFrameworkBundleID, NSURL* searchURL) { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index c8a0dc6fe4..6a662381fd 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -23,7 +23,7 @@ constexpr char kTextPlainFormat[] = "text/plain"; const UInt32 kKeyPressClickSoundId = 1306; #if not APPLICATION_EXTENSION_API_ONLY -const NSString* searchURLPrefix = @"x-web-search://?"; +NSString* const kSearchURLPrefix = @"x-web-search://?"; #endif } // namespace @@ -226,7 +226,7 @@ static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) { NSString* escapedText = [searchTerm stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; - NSString* searchURL = [NSString stringWithFormat:@"%@%@", searchURLPrefix, escapedText]; + NSString* searchURL = [NSString stringWithFormat:@"%@%@", kSearchURLPrefix, escapedText]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:searchURL] options:@{}