-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,486 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// AppDelegate.swift | ||
// Example with Mac | ||
// | ||
// Created by Artur Mkrtchyan on 3/20/20. | ||
// Copyright © 2020 CocoaPods. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
import Unrealm | ||
|
||
@NSApplicationMain | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
|
||
var windowController: WindowController! | ||
|
||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
|
||
Realm.registerRealmables(ToDoItem.self) | ||
|
||
windowController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "WindowController") as? WindowController | ||
windowController.showWindow(self) | ||
windowController.window?.makeKey() | ||
} | ||
|
||
func applicationWillTerminate(_ aNotification: Notification) { | ||
// Insert code here to tear down your application | ||
} | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
Example/Example with Mac/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "mac", | ||
"size" : "16x16", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "16x16", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "32x32", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "32x32", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "128x128", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "128x128", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "256x256", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "256x256", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "512x512", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "512x512", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSMinimumSystemVersion</key> | ||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2020 CocoaPods. All rights reserved.</string> | ||
<key>NSMainStoryboardFile</key> | ||
<string>Main</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
<key>NSSupportsAutomaticTermination</key> | ||
<true/> | ||
<key>NSSupportsSuddenTermination</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// TableCellViewModel.swift | ||
// Example with Mac | ||
// | ||
// Created by Artur Mkrtchyan on 3/20/20. | ||
// Copyright © 2020 CocoaPods. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class TableCellViewModel: NSObject { | ||
@objc dynamic var id: String | ||
@objc dynamic var text: String | ||
@objc dynamic var isCompleted: Bool | ||
|
||
init(item: ToDoItem) { | ||
self.id = item.id | ||
self.text = item.text | ||
self.isCompleted = item.isCompleted | ||
super.init() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// ViewController.swift | ||
// Example with Mac | ||
// | ||
// Created by Artur Mkrtchyan on 3/20/20. | ||
// Copyright © 2020 arturdev. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
import Unrealm | ||
|
||
class ViewController: NSViewController { | ||
|
||
@objc dynamic var items: [TableCellViewModel] = [] | ||
|
||
private var results: Unrealm.Results<ToDoItem>? | ||
private var resultsToken: NotificationToken? | ||
|
||
@IBOutlet weak var tableView: NSTableView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
results = ToDoItem.all().sorted(byKeyPath: "id") | ||
resultsToken = results?.observe { [weak self] _ in | ||
self?.regenerateCellVMs() | ||
} | ||
} | ||
|
||
private func regenerateCellVMs() { | ||
guard let results = results else { return } | ||
items = Array(results).map(TableCellViewModel.init) | ||
} | ||
|
||
@IBAction func completeActions(_ sender: NSButton) { | ||
guard let results = results else { return } | ||
let row = tableView.row(for: sender) | ||
var item = results[row] | ||
item.toggleCompleted() | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// WindowController.swift | ||
// Example with Mac | ||
// | ||
// Created by Artur Mkrtchyan on 3/20/20. | ||
// Copyright © 2020 arturdev. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
class WindowController: NSWindowController { | ||
|
||
@IBAction func addTapped(_ sender: Any) { | ||
let alert = NSAlert() | ||
alert.messageText = "Please enter a value" | ||
alert.addButton(withTitle: "Save") | ||
alert.addButton(withTitle: "Cancel") | ||
|
||
let inputTextField = NSTextField(frame: NSRect(x: 0, y: 0, width: 300, height: 24)) | ||
inputTextField.placeholderString = "Enter text" | ||
alert.accessoryView = inputTextField | ||
alert.beginSheetModal(for: NSApp.keyWindow!) { (modalResponse) in | ||
if modalResponse == .alertFirstButtonReturn { | ||
let text = inputTextField.stringValue | ||
ToDoItem.add(text: text) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.