Skip to content

Commit bb1cfe4

Browse files
stuartmorgan-gmauricioluz
authored andcommitted
[shared_preferences] Merge iOS and macOS implementations (flutter#6920)
This merges `shared_preferences_ios` and `shared_preferences_macos` into a new `shared_preferences_foundations` that replaces both of those packages, as described in flutter/flutter#117941: - Renames `shared_preferences_macos` to `shared_prefrences_foundation`, since the macOS implementation is the Swift implementation, which is what we want to use going forward. - Moves the implementation files to a shared directory (called `darwin/` in anticipation of flutter/flutter#115337), adjusting the code and podspec slightly to make it iOS-compatible - Adds iOS support to the example, via `flutter create`-ing a new iOS example and wiring it up to use the existing native unit test. (This was done instead of moving the example from `shared_preferences_ios` since it seemed better to have the example be in Swift as well now.) - Removes `shared_preferences_ios`. Once this lands and has been published, a follow-up will update `shared_preferences` to use this new package instead of the other two, and the old ones will be marked as deprecated on pub.dev. Part of flutter/flutter#117941
1 parent d38fb6c commit bb1cfe4

File tree

139 files changed

+421
-1646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+421
-1646
lines changed

CODEOWNERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ packages/ios_platform_images/ios/** @jmagman
5151
packages/local_auth/local_auth_ios/** @hellohuanlin
5252
packages/path_provider/path_provider_ios/** @jmagman
5353
packages/quick_actions/quick_actions_ios/** @hellohuanlin
54-
packages/shared_preferences/shared_preferences_ios/** @cyanglaz
54+
packages/shared_preferences/shared_preferences_foundation/** @cyanglaz
5555
packages/url_launcher/url_launcher_ios/** @jmagman
5656
packages/video_player/video_player_avfoundation/** @hellohuanlin
5757
packages/webview_flutter/webview_flutter_wkwebview/** @cyanglaz
@@ -65,7 +65,6 @@ packages/url_launcher/url_launcher_linux/** @cbracken
6565
# - macOS
6666
packages/file_selector/file_selector_macos/** @cbracken
6767
packages/path_provider/path_provider_macos/** @cbracken
68-
packages/shared_preferences/shared_preferences_macos/** @cbracken
6968
packages/url_launcher/url_launcher_macos/** @cbracken
7069

7170
# - Windows
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 2.1.0
2+
3+
* Renames the package previously published as
4+
[`shared_preferences_macos`](https://pub.dev/packages/shared_preferences_macos)
5+
* Adds iOS support.

packages/shared_preferences/shared_preferences_ios/README.md renamed to packages/shared_preferences/shared_preferences_foundation/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# shared\_preferences\_ios
1+
# shared\_preferences\_foundation
22

3-
The iOS implementation of [`shared_preferences`][1].
3+
The iOS and macOS implementation of [`shared_preferences`][1].
44

55
## Usage
66

packages/shared_preferences/shared_preferences_macos/macos/Classes/SharedPreferencesPlugin.swift renamed to packages/shared_preferences/shared_preferences_foundation/darwin/Classes/SharedPreferencesPlugin.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import FlutterMacOS
65
import Foundation
76

7+
#if os(iOS)
8+
import Flutter
9+
#elseif os(macOS)
10+
import FlutterMacOS
11+
#endif
12+
813
public class SharedPreferencesPlugin: NSObject, FlutterPlugin, UserDefaultsApi {
914
public static func register(with registrar: FlutterPluginRegistrar) {
1015
let instance = SharedPreferencesPlugin()
11-
UserDefaultsApiSetup.setUp(binaryMessenger: registrar.messenger, api: instance)
16+
// Workaround for https://github.com/flutter/flutter/issues/118103.
17+
#if os(iOS)
18+
let messenger = registrar.messenger()
19+
#else
20+
let messenger = registrar.messenger
21+
#endif
22+
UserDefaultsApiSetup.setUp(binaryMessenger: messenger, api: instance)
1223
}
1324

1425
func getAll() -> [String? : Any?] {
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import FlutterMacOS
65
import XCTest
7-
@testable import shared_preferences_macos
6+
7+
#if os(iOS)
8+
import Flutter
9+
#elseif os(macOS)
10+
import FlutterMacOS
11+
#endif
12+
13+
@testable import shared_preferences_foundation
814

915
class RunnerTests: XCTestCase {
1016
func testSetAndGet() throws {

packages/shared_preferences/shared_preferences_macos/macos/shared_preferences_macos.podspec renamed to packages/shared_preferences/shared_preferences_foundation/darwin/shared_preferences_foundation.podspec

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
33
#
44
Pod::Spec.new do |s|
5-
s.name = 'shared_preferences_macos'
5+
s.name = 'shared_preferences_foundation'
66
s.version = '0.0.1'
7-
s.summary = 'macOS implementation of the shared_preferences plugin.'
7+
s.summary = 'iOS and macOS implementation of the shared_preferences plugin.'
88
s.description = <<-DESC
99
Wraps NSUserDefaults, providing a persistent store for simple key-value pairs.
1010
DESC
11-
s.homepage = 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_macos'
11+
s.homepage = 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_foundation'
1212
s.license = { :type => 'BSD', :file => '../LICENSE' }
1313
s.author = { 'Flutter Team' => '[email protected]' }
14-
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_macos' }
14+
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_foundation' }
1515
s.source_files = 'Classes/**/*'
16-
s.dependency 'FlutterMacOS'
17-
18-
s.platform = :osx, '10.11'
16+
s.ios.dependency 'Flutter'
17+
s.osx.dependency 'FlutterMacOS'
18+
s.ios.deployment_target = '9.0'
19+
s.osx.deployment_target = '10.11'
1920
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
2021
s.swift_version = '5.0'
2122

2223
end
23-

packages/shared_preferences/shared_preferences_ios/example/.gitignore renamed to packages/shared_preferences/shared_preferences_foundation/example/.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.buildlog/
99
.history
1010
.svn/
11+
migrate_working_dir/
1112

1213
# IntelliJ related
1314
*.iml
@@ -31,9 +32,6 @@
3132
.pub/
3233
/build/
3334

34-
# Web related
35-
lib/generated_plugin_registrant.dart
36-
3735
# Symbolication related
3836
app.*.symbols
3937

0 commit comments

Comments
 (0)