Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[shared_preferences] Merge iOS and macOS implementations (#6920)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stuartmorgan committed Jan 10, 2023
1 parent 1de6477 commit fb40581
Show file tree
Hide file tree
Showing 139 changed files with 421 additions and 1,646 deletions.
3 changes: 1 addition & 2 deletions CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -51,7 +51,7 @@ packages/ios_platform_images/ios/** @jmagman
packages/local_auth/local_auth_ios/** @hellohuanlin
packages/path_provider/path_provider_ios/** @jmagman
packages/quick_actions/quick_actions_ios/** @hellohuanlin
packages/shared_preferences/shared_preferences_ios/** @cyanglaz
packages/shared_preferences/shared_preferences_foundation/** @cyanglaz
packages/url_launcher/url_launcher_ios/** @jmagman
packages/video_player/video_player_avfoundation/** @hellohuanlin
packages/webview_flutter/webview_flutter_wkwebview/** @cyanglaz
Expand All @@ -65,7 +65,6 @@ packages/url_launcher/url_launcher_linux/** @cbracken
# - macOS
packages/file_selector/file_selector_macos/** @cbracken
packages/path_provider/path_provider_macos/** @cbracken
packages/shared_preferences/shared_preferences_macos/** @cbracken
packages/url_launcher/url_launcher_macos/** @cbracken

# - Windows
Expand Down
@@ -0,0 +1,5 @@
## 2.1.0

* Renames the package previously published as
[`shared_preferences_macos`](https://pub.dev/packages/shared_preferences_macos)
* Adds iOS support.
@@ -1,6 +1,6 @@
# shared\_preferences\_ios
# shared\_preferences\_foundation

The iOS implementation of [`shared_preferences`][1].
The iOS and macOS implementation of [`shared_preferences`][1].

## Usage

Expand Down
Expand Up @@ -2,13 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import FlutterMacOS
import Foundation

#if os(iOS)
import Flutter
#elseif os(macOS)
import FlutterMacOS
#endif

public class SharedPreferencesPlugin: NSObject, FlutterPlugin, UserDefaultsApi {
public static func register(with registrar: FlutterPluginRegistrar) {
let instance = SharedPreferencesPlugin()
UserDefaultsApiSetup.setUp(binaryMessenger: registrar.messenger, api: instance)
// Workaround for https://github.com/flutter/flutter/issues/118103.
#if os(iOS)
let messenger = registrar.messenger()
#else
let messenger = registrar.messenger
#endif
UserDefaultsApiSetup.setUp(binaryMessenger: messenger, api: instance)
}

func getAll() -> [String? : Any?] {
Expand Down
Expand Up @@ -2,9 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import FlutterMacOS
import XCTest
@testable import shared_preferences_macos

#if os(iOS)
import Flutter
#elseif os(macOS)
import FlutterMacOS
#endif

@testable import shared_preferences_foundation

class RunnerTests: XCTestCase {
func testSetAndGet() throws {
Expand Down
Expand Up @@ -2,22 +2,22 @@
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'shared_preferences_macos'
s.name = 'shared_preferences_foundation'
s.version = '0.0.1'
s.summary = 'macOS implementation of the shared_preferences plugin.'
s.summary = 'iOS and macOS implementation of the shared_preferences plugin.'
s.description = <<-DESC
Wraps NSUserDefaults, providing a persistent store for simple key-value pairs.
DESC
s.homepage = 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_macos'
s.homepage = 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_foundation'
s.license = { :type => 'BSD', :file => '../LICENSE' }
s.author = { 'Flutter Team' => 'flutter-dev@googlegroups.com' }
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_macos' }
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_foundation' }
s.source_files = 'Classes/**/*'
s.dependency 'FlutterMacOS'

s.platform = :osx, '10.11'
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'

end

Expand Up @@ -8,6 +8,7 @@
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
Expand All @@ -31,9 +32,6 @@
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

Expand Down
Expand Up @@ -9,7 +9,7 @@ import 'package:shared_preferences_platform_interface/shared_preferences_platfor
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('SharedPreferencesIos', () {
group('SharedPreferencesFoundation', () {
const Map<String, Object> kTestValues = <String, Object>{
'flutter.String': 'hello world',
'flutter.bool': true,
Expand Down
@@ -1,3 +1,4 @@
**/dgph
*.mode1v3
*.mode2v3
*.moved-aside
Expand All @@ -18,6 +19,7 @@ Flutter/App.framework
Flutter/Flutter.framework
Flutter/Flutter.podspec
Flutter/Generated.xcconfig
Flutter/ephemeral/
Flutter/app.flx
Flutter/app.zip
Flutter/flutter_assets/
Expand Down
Expand Up @@ -20,11 +20,7 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
@@ -1,3 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
@@ -1,3 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down Expand Up @@ -28,6 +28,9 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe
flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
Expand Down

0 comments on commit fb40581

Please sign in to comment.