RBSRealmBrowser 0.4.0

RBSRealmBrowser 0.4.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2019年9月
SPM支持 SPM

Maintained by Max Baumbach.



  • By
  • Max Baumbach

RBSRealmBrowser

CI Status Version License Platform

RBSRealmBrowser 基于 NBNRealmBrowser,由 Nerdish by Nature 提供支持。它是一个简单轻量级浏览器,可以让您查看 iOS 设备或模拟器中当前 Realmd 数据库中的对象。只需切换到编辑模式即可简单地编辑现有对象的属性值。

特性

  • 快速浏览 Realmd 对象
  • 编辑 Realmd 对象
  • 删除 Realmd 对象
  • 搜索特定值
  • 快捷操作(从主屏幕启动浏览器)
  • 仅对特定类打开 Realmd 浏览器(例如,仅想检查 Person 类)

以下类型目前支持编辑对象

  • 布尔值
  • 字符串
  • 整数
  • 浮点数
  • 双精度浮点数

用途

要运行示例项目,请克隆存储库,然后首先从示例目录运行 pod install

此浏览器仅与 RealmSwift 兼容,因为 Realm (Objective-C) 和 RealmSwift '不可互操作,并且不支持一起使用'。

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // add a UIBarButtonItem 
        let bbi = UIBarButtonItem(title: "Open", style: UIBarButtonItemStyle.plain, target: self, action:   #selector(ViewController.openBrowser))
        navigationItem.rightBarButtonItem = bbi
    }

    @objc func openBrowser() {
        guard let realmBrowser = RBSRealmBrowser.realmBrowser(showing: ["Person"]) else { return }
        present(realmBrowser, animated: true, completion: nil)
    }
}

使用以下方法之一浏览 Realm 数据库

所有这些便利方法都附带一个使用 classes 选项的第二个方法。如果您希望将结果限制为特定类,请使用这些方法。

如果您传递 nil,将显示所有对象。《[String] 必须由类名组成,并且它们必须匹配。

如果您想快速访问默认 Realm 数据库中的所有对象,请使用以下两种方法之一

// get the RealmBrowser for default Realm 
public static func realmBrowser() -> UINavigationController?
// get the RealmBrowser for default Realm, filtered by an optional class names array 
public static func realmBrowser(showing classes:[String]?) -> UINavigationController?

如果您想指定一个 Realm,请使用以下两种方法之一

// get the RealmBrowser for Realm 
public static func realmBrowserForRealm(_ realm: Realm) -> UINavigationController?
// Pass an optional array of class names you want to display & your realm
public static func realmBrowserForRealm(_ realm: Realm, showing filteredClasses:[String]?) -> UINavigationController?

如果您想访问给定 URL 的 Realm,请使用以下方法之一

// get the RealmBrowser for Realm at a specific url
public static func realmBroswerForRealmURL(_ url: URL) -> UINavigationController?
// Same as the above but you can pass an optional [String] containing Class names
public static func realmBrowser(showing classes:[String]?,aURL URL:URL) -> UINavigationController?

快速操作

本最新版本支持 iOS 9.0 及以上版本的动态快速操作。要使用快速操作,请将以下代码添加到 AppDelegate 的 applicationDidFinishLaunching(:) 方法中。

// add the realmbrowser quick action to your shortcut items array
   if #available(iOS 9.0, *) {
       application.shortcutItems = [RBSRealmBrowser.addBrowserQuickAction()]
   } else {
       // Fallback on earlier versions
   }

现在处理操作

    func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        
        // handle the quick action
        guard let rb = RBSRealmBrowser.realmBrowser() else {
            print("realm browser is nil!")
            return
        }
        let vc = (window?.rootViewController)! as UIViewController
        vc.present(rb, animated: true)
    }

尝试

要尝试示例项目,请克隆存储库,然后首先从 Example 目录运行 pod try

要求

  • Xcode 8
  • iOS 9.0+
  • Swift 3.0(对于任何 0.1.4 之后的发布版本)
  • Swift 4.0(对于任何 0.1.9 之后的发布版本)
  • Swift 4.1(对于任何 0.2.2 之后的发布版本)
  • Swift 4.2(对于任何 0.2.4 之后的发布版本)
  • Swift 5.0(对于任何 0.2.9 之后的发布版本)

安装

RBSRealmBrowser可以通过CocoaPods获取。要安装它,只需在Podfile中添加以下行

pod 'RBSRealmBrowser', :configurations => ['Debug']

未来特性

路线图上的内容...🚀

  • 测试
  • 能够创建对象
  • 清理
  • 如果后台发生更新,则实时重新加载浏览器
  • 布局改进
  • 基本搜索
  • 更好的搜索

文档

可用的方法文档在这里

为Android项目的RealmBrowser

Jonas Rottmann开发的为Android项目提供的Realm Browser可在jonasrottmann/realm-browser获得

作者

Max Baumbach, [email protected]

许可

RBSRealmBrowser遵循MIT许可协议。更多详细信息请参阅LICENSE文件。