Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix many compiler warnings #2257

Merged
merged 16 commits into from
Mar 1, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ playground.xcworkspace
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm
LocalPackages/*/Package.resolved

.build/

Expand Down
2 changes: 1 addition & 1 deletion .xcode-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15.1
15.2
14 changes: 7 additions & 7 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
14505A08256084EF00272CC6 /* UserAgent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14505A07256084EF00272CC6 /* UserAgent.swift */; };
1456D6E124EFCBC300775049 /* TabBarCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1456D6E024EFCBC300775049 /* TabBarCollectionView.swift */; };
14D9B8FB24F7E089000D4D13 /* AddressBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D9B8F924F7E089000D4D13 /* AddressBarViewController.swift */; };
1D02633628D8A9A9005CBB41 /* BWEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D02633528D8A9A9005CBB41 /* BWEncryption.m */; };
1D02633628D8A9A9005CBB41 /* BWEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D02633528D8A9A9005CBB41 /* BWEncryption.m */; settings = {COMPILER_FLAGS = "-Wno-deprecated -Wno-strict-prototypes"; }; };
1D074B272909A433006E4AC3 /* PasswordManagerCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D074B262909A433006E4AC3 /* PasswordManagerCoordinator.swift */; };
1D12F2E2298BC660009A65FD /* InternalUserDeciderStoreMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D12F2E1298BC660009A65FD /* InternalUserDeciderStoreMock.swift */; };
1D1A33492A6FEB170080ACED /* BurnerMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1A33482A6FEB170080ACED /* BurnerMode.swift */; };
Expand Down Expand Up @@ -713,7 +713,6 @@
3706FDE0293F661700E42796 /* TabIndexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D2377B287EBDA300BCE03B /* TabIndexTests.swift */; };
3706FDE1293F661700E42796 /* AdjacentItemEnumeratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37534CA42811987D002621E7 /* AdjacentItemEnumeratorTests.swift */; };
3706FDE2293F661700E42796 /* PixelArgumentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6DA44222616CABC00DD1EC2 /* PixelArgumentsTests.swift */; };
3706FDE3293F661700E42796 /* History.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = AAE75278263B046100B973F8 /* History.xcdatamodeld */; };
3706FDE4293F661700E42796 /* TabLazyLoaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37534C9D28104D9B002621E7 /* TabLazyLoaderTests.swift */; };
3706FDE5293F661700E42796 /* URLEventHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85F1B0C825EF9759004792B6 /* URLEventHandlerTests.swift */; };
3706FDE6293F661700E42796 /* BookmarkOutlineViewDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9292B32667103000AD2C21 /* BookmarkOutlineViewDataSourceTests.swift */; };
Expand Down Expand Up @@ -1464,7 +1463,7 @@
4B957A012AC7AE700062CA31 /* SafariDataImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB99CFD26FE191E001E4761 /* SafariDataImporter.swift */; };
4B957A022AC7AE700062CA31 /* WaitlistViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9DB00C2A983B24000927DB /* WaitlistViewModel.swift */; };
4B957A032AC7AE700062CA31 /* LocalBookmarkStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 987799F829999973005D8EB6 /* LocalBookmarkStore.swift */; };
4B957A042AC7AE700062CA31 /* BWEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D02633528D8A9A9005CBB41 /* BWEncryption.m */; };
4B957A042AC7AE700062CA31 /* BWEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D02633528D8A9A9005CBB41 /* BWEncryption.m */; settings = {COMPILER_FLAGS = "-Wno-deprecated -Wno-strict-prototypes"; }; };
4B957A052AC7AE700062CA31 /* StatisticsLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = B69B50342726A11F00758A2B /* StatisticsLoader.swift */; };
4B957A072AC7AE700062CA31 /* PrivacyPreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CD54C127F2FDD100F1F7B9 /* PrivacyPreferencesModel.swift */; };
4B957A082AC7AE700062CA31 /* LocalUnprotectedDomains.swift in Sources */ = {isa = PBXBuildFile; fileRef = 336B39E22726B4B700C417D3 /* LocalUnprotectedDomains.swift */; };
Expand Down Expand Up @@ -2573,7 +2572,6 @@
AAEC74B42642C69300C2EFBC /* HistoryCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEC74B32642C69300C2EFBC /* HistoryCoordinatorTests.swift */; };
AAEC74B62642CC6A00C2EFBC /* HistoryStoringMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEC74B52642CC6A00C2EFBC /* HistoryStoringMock.swift */; };
AAEC74B82642E43800C2EFBC /* HistoryStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEC74B72642E43800C2EFBC /* HistoryStoreTests.swift */; };
AAEC74BC2642F0F800C2EFBC /* History.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = AAE75278263B046100B973F8 /* History.xcdatamodeld */; };
AAECA42024EEA4AC00EFA63A /* IndexPathExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAECA41F24EEA4AC00EFA63A /* IndexPathExtension.swift */; };
AAEEC6A927088ADB008445F7 /* FireCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEEC6A827088ADB008445F7 /* FireCoordinator.swift */; };
AAEF6BC8276A081C0024DCF4 /* FaviconSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEF6BC7276A081C0024DCF4 /* FaviconSelector.swift */; };
Expand Down Expand Up @@ -8847,7 +8845,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1520;
LastUpgradeCheck = 1400;
LastUpgradeCheck = 1520;
ORGANIZATIONNAME = DuckDuckGo;
TargetAttributes = {
3706FDD3293F661700E42796 = {
Expand Down Expand Up @@ -9268,6 +9266,7 @@
/* Begin PBXShellScriptBuildPhase section */
3121F62B2B64266A002F706A /* Copy Swift Package resources */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -9362,6 +9361,7 @@
};
4B2D067D2A13341200DE1F49 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -9436,6 +9436,7 @@
};
4BBA2D272B6AC09D00F6A470 /* Embed Login Items */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -9492,6 +9493,7 @@
};
7B557F2A2B8CA2A400099746 /* Embed Debug-only Network Extensions */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -10337,7 +10339,6 @@
3706FDE1293F661700E42796 /* AdjacentItemEnumeratorTests.swift in Sources */,
3706FDE2293F661700E42796 /* PixelArgumentsTests.swift in Sources */,
4B9DB0572A983B55000927DB /* MockNotificationService.swift in Sources */,
3706FDE3293F661700E42796 /* History.xcdatamodeld in Sources */,
3706FDE4293F661700E42796 /* TabLazyLoaderTests.swift in Sources */,
3706FDE5293F661700E42796 /* URLEventHandlerTests.swift in Sources */,
3706FDE6293F661700E42796 /* BookmarkOutlineViewDataSourceTests.swift in Sources */,
Expand Down Expand Up @@ -12285,7 +12286,6 @@
37D2377C287EBDA300BCE03B /* TabIndexTests.swift in Sources */,
37534CA52811987D002621E7 /* AdjacentItemEnumeratorTests.swift in Sources */,
B6DA44232616CABC00DD1EC2 /* PixelArgumentsTests.swift in Sources */,
AAEC74BC2642F0F800C2EFBC /* History.xcdatamodeld in Sources */,
56B234BF2A84EFD200F2A1CC /* NavigationBarUrlExtensionsTests.swift in Sources */,
37534C9E28104D9B002621E7 /* TabLazyLoaderTests.swift in Sources */,
B6619EF62B10DFF700CD9186 /* InstructionsFormatParserTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1520"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1520"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1520"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1520"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1520"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1520"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel

#if SUBSCRIPTION
Task {
var defaultEnvironment = SubscriptionPurchaseEnvironment.ServiceEnvironment.default
let defaultEnvironment = SubscriptionPurchaseEnvironment.ServiceEnvironment.default

let currentEnvironment = UserDefaultsWrapper(key: .subscriptionEnvironment,
defaultValue: defaultEnvironment).wrappedValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21512" systemVersion="22A380" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22522" systemVersion="23C71" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="BookmarkManagedObject" representedClassName="BookmarkManagedObject" syncable="YES" codeGenerationType="class">
<attribute name="dateAdded" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="faviconEncrypted" optional="YES" attributeType="Transformable" valueTransformerName="NSImageTransformer"/>
<attribute name="faviconEncrypted" optional="YES" attributeType="Transformable" valueTransformerName="">
<userInfo>
<entry key="transformer" value="NSImageTransformer"/>
</userInfo>
</attribute>
<attribute name="id" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="isFavorite" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isFolder" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="titleEncrypted" attributeType="Transformable" valueTransformerName="NSStringTransformer"/>
<attribute name="urlEncrypted" optional="YES" attributeType="Transformable" valueTransformerName="NSURLTransformer"/>
<attribute name="titleEncrypted" attributeType="Transformable" valueTransformerName="">
<userInfo>
<entry key="transformer" value="NSStringTransformer"/>
</userInfo>
</attribute>
<attribute name="urlEncrypted" optional="YES" attributeType="Transformable" valueTransformerName="">
<userInfo>
<entry key="transformer" value="NSURLTransformer"/>
</userInfo>
</attribute>
<relationship name="children" optional="YES" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="BookmarkManagedObject" inverseName="parentFolder" inverseEntity="BookmarkManagedObject"/>
<relationship name="favorites" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="BookmarkManagedObject" inverseName="favoritesFolder" inverseEntity="BookmarkManagedObject"/>
<relationship name="favoritesFolder" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="BookmarkManagedObject" inverseName="favorites" inverseEntity="BookmarkManagedObject"/>
Expand Down
81 changes: 70 additions & 11 deletions DuckDuckGo/Common/Database/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import AppKit
import BrowserServicesKit
import Foundation
import CoreData
import Foundation
import Persistence

final class Database {
Expand All @@ -41,17 +41,15 @@ final class Database {

static func makeDatabase() -> (CoreDataDatabase?, Error?) {
func makeDatabase(keyStore: EncryptionKeyStoring, containerLocation: URL) -> (CoreDataDatabase?, Error?) {
do {
try EncryptedValueTransformer<NSImage>.registerTransformer(keyStore: keyStore)
try EncryptedValueTransformer<NSString>.registerTransformer(keyStore: keyStore)
try EncryptedValueTransformer<NSURL>.registerTransformer(keyStore: keyStore)
try EncryptedValueTransformer<NSNumber>.registerTransformer(keyStore: keyStore)
try EncryptedValueTransformer<NSError>.registerTransformer(keyStore: keyStore)
try EncryptedValueTransformer<NSData>.registerTransformer(keyStore: keyStore)
} catch {
return (nil, error)
}
let mainModel = NSManagedObjectModel.mergedModel(from: [.main])!
_=mainModel.registerValueTransformers(withAllowedPropertyClasses: [
NSImage.self,
NSString.self,
NSURL.self,
NSNumber.self,
NSError.self,
NSData.self
], keyStore: keyStore)
let httpsUpgradeModel = HTTPSUpgrade.managedObjectModel

return (CoreDataDatabase(name: Constants.databaseName,
Expand Down Expand Up @@ -118,6 +116,67 @@ extension Array where Element == CoreDataErrorsParser.ErrorInfo {
}
}

extension ValueTransformer {

static func registerValueTransformer(for propertyClass: AnyClass, with keyStore: EncryptionKeyStoring) -> NSValueTransformerName {
guard let encodableType = propertyClass as? (NSObject & NSSecureCoding).Type else {
fatalError("Unsupported type")
}
func registerValueTransformer<T: NSObject & NSSecureCoding>(for type: T.Type) -> NSValueTransformerName {
(try? EncryptedValueTransformer<T>.registerTransformer(keyStore: keyStore))!
return EncryptedValueTransformer<T>.transformerName
}
return registerValueTransformer(for: encodableType)
}

}

extension NSManagedObjectModel {

private static let transformerUserInfoKey = "transformer"
func registerValueTransformers(withAllowedPropertyClasses allowedPropertyClasses: [AnyClass]? = nil,
keyStore: EncryptionKeyStoring) -> [NSValueTransformerName] {
var registeredTransformers = [NSValueTransformerName]()
let allowedPropertyClassNames = allowedPropertyClasses.map { Set($0.map(NSStringFromClass)) }

// fix "no NSValueTransformer with class name 'X'" warnings
// https://stackoverflow.com/a/77623593/748453
for entity in self.entities {
for property in entity.properties {
guard let property = property as? NSAttributeDescription, property.attributeType == .transformableAttributeType else { continue }

let transformerName: String
if let valueTransformerName = property.valueTransformerName, !valueTransformerName.isEmpty {
transformerName = valueTransformerName
} else if let transformerUserInfoValue = property.userInfo?[Self.transformerUserInfoKey] as? String, !transformerUserInfoValue.isEmpty {
transformerName = transformerUserInfoValue
property.userInfo?.removeValue(forKey: Self.transformerUserInfoKey)
property.valueTransformerName = transformerName
} else {
assertionFailure("Transformer (User Info `transformer` key) not set for \(entity).\(property)")
continue
}

guard ValueTransformer(forName: .init(rawValue: transformerName)) == nil else { continue }

let propertyClassName = transformerName.dropping(suffix: "Transformer")
assert(propertyClassName != transformerName, "Expected Transformer name like `NSStringTransformer`")
guard allowedPropertyClassNames?.contains(propertyClassName) != false,
let propertyClass = NSClassFromString(propertyClassName) else {
assertionFailure("Invalid class name `\(propertyClassName)` for \(transformerName)")
continue
}

let transformer = ValueTransformer.registerValueTransformer(for: propertyClass, with: keyStore)
assert(ValueTransformer(forName: .init(transformerName)) != nil)
registeredTransformers.append(transformer)
}
}
return registeredTransformers
}

}

extension NSManagedObjectContext {

func save(onErrorFire event: Pixel.Event.Debug) throws {
Expand Down
Loading
Loading