Skip to content

Commit 7f43511

Browse files
committed
feat: update search bar placement handling in MainVC and remove legacy toolbar integration method
refactor: streamline supported languages cache management in CrowdinSupportedLanguages chore: remove unused environment variable from Tests scheme
1 parent 125ea84 commit 7f43511

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

Example/AppleReminders/Controllers/MainVC.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,13 @@ final class MainVC: UIViewController {
188188
searchController?.obscuresBackgroundDuringPresentation = false
189189
searchController?.searchBar.placeholder = "Search".localized
190190
navigationItem.searchController = searchController
191-
if #available(iOS 26.0, *) {
192-
// Keep search UI in the navigation bar to avoid toolbar integration overlapping the footer.
191+
if #available(iOS 16.0, *) {
192+
// Keep search UI in the navigation bar
193193
navigationItem.preferredSearchBarPlacement = .stacked
194-
navigationItem.setSearchBarPlacementAllowsToolbarIntegration(false)
195194
}
196195
}
197196
}
198197

199-
private extension UINavigationItem {
200-
func setSearchBarPlacementAllowsToolbarIntegration(_ value: Bool) {
201-
let selector = NSSelectorFromString("setSearchBarPlacementAllowsToolbarIntegration:")
202-
guard responds(to: selector) else { return }
203-
setValue(value, forKey: "searchBarPlacementAllowsToolbarIntegration")
204-
}
205-
}
206-
207198
//MARK: Datasource
208199
extension MainVC {
209200
func setupDatasource() {

Sources/CrowdinSDK/Providers/Crowdin/SupportedLanguages/CrowdinSupportedLanguages.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ class CrowdinSupportedLanguages {
8383
UserDefaults.standard.removeObject(forKey: Keys.lastUpdatedDate.rawValue)
8484
UserDefaults.standard.synchronize()
8585

86+
// Only remove legacy (pre-hash) supported languages cache files.
87+
// Legacy files have the pattern "SupportedLanguages.json" (without a hash).
88+
let legacyFileName = Strings.supportedLanguages.rawValue + FileType.json.extension
8689
let folderPath = CrowdinFolder.shared.path + String.pathDelimiter + Strings.crowdin.rawValue
87-
if let files = try? FileManager.default.contentsOfDirectory(atPath: folderPath) {
88-
for file in files where file.starts(with: Strings.supportedLanguages.rawValue) && !file.contains(hash) {
89-
let fullPath = folderPath + String.pathDelimiter + file
90-
try? FileManager.default.removeItem(atPath: fullPath)
91-
}
92-
}
90+
let legacyFilePath = folderPath + String.pathDelimiter + legacyFileName
91+
try? FileManager.default.removeItem(atPath: legacyFilePath)
9392
}
9493

9594
func updateSupportedLanguagesIfNeeded(manifestTimestamp: TimeInterval?, completion: (() -> Void)? = nil, error: ((Error) -> Void)? = nil) {
@@ -257,6 +256,12 @@ class CrowdinSupportedLanguages {
257256
if let languages = languages {
258257
self._supportedLanguages = languages
259258
self.saveSupportedLanguages()
259+
} else if self._supportedLanguages == nil {
260+
// On 304 (Not Modified), load from cache if we don't have it in memory yet
261+
let cachedData = try? Data(contentsOf: URL(fileURLWithPath: self.filePath))
262+
if let data = cachedData {
263+
self._supportedLanguages = try? JSONDecoder().decode([DistributionLanguage].self, from: data)
264+
}
260265
}
261266
let completions = self._completions
262267
self._errors.removeAll()
@@ -278,8 +283,19 @@ class CrowdinSupportedLanguages {
278283
}
279284

280285
fileprivate func saveSupportedLanguages() {
281-
guard let languages = _supportedLanguages as? [DistributionLanguage],
282-
let data = try? JSONEncoder().encode(languages) else { return }
286+
// Read the current supported languages on the serial queue for thread safety
287+
let currentLanguages: [CrowdinLanguage]? = queue.sync { _supportedLanguages }
288+
289+
guard let crowdlanguages = currentLanguages else { return }
290+
291+
// Cast each element individually to DistributionLanguage. A direct cast from
292+
// [CrowdinLanguage] to [DistributionLanguage] will always fail for existential arrays.
293+
let distributionLanguages = crowdlanguages.compactMap { $0 as? DistributionLanguage }
294+
295+
// Ensure all elements were successfully cast; if not, avoid writing a partial cache.
296+
guard distributionLanguages.count == crowdlanguages.count,
297+
let data = try? JSONEncoder().encode(distributionLanguages) else { return }
298+
283299
try? data.write(to: URL(fileURLWithPath: filePath), options: Data.WritingOptions.atomic)
284300
}
285301

Tests/Tests.xcodeproj/xcshareddata/xcschemes/TestsTests.xcscheme

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@
8080
debugDocumentVersioning = "YES"
8181
debugServiceExtension = "internal"
8282
allowLocationSimulation = "YES">
83-
<EnvironmentVariables>
84-
<EnvironmentVariable
85-
key = "RUN_INTEGRATION_TESTS"
86-
value = "1"
87-
isEnabled = "YES">
88-
</EnvironmentVariable>
89-
</EnvironmentVariables>
9083
</LaunchAction>
9184
<ProfileAction
9285
buildConfiguration = "Release"

0 commit comments

Comments
 (0)