Skip to content

Instantly share code, notes, and snippets.

@hsylife
Last active November 25, 2016 12:57
Show Gist options
  • Save hsylife/8baed1fb58fb38949abe9ed92293eb86 to your computer and use it in GitHub Desktop.
Save hsylife/8baed1fb58fb38949abe9ed92293eb86 to your computer and use it in GitHub Desktop.
How to exchange Realm data between watchOS and iOS ref: http://qiita.com/hsylife/items/26629e65bf66d79cd311
import RealmSwift
public class Field: Object {
public dynamic var text: String?
}
target 'SampleRealmOnWatchOS3' do
dynamic frameworks
use_frameworks!
pod 'RealmSwift'
end
target 'SampleWatchApp_Extension' do
use_frameworks!
platform :watchos, '2.0'
pod 'RealmSwift'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
class ViewController: UIViewController, WCSessionDelegate {
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
if let text = message["text"] as! String?{
messageLabel.setText(text)
}
replyHandler(["reply" : "OK"])
}
func sendMessage(){
if WCSession.default().isReachable {
let applicationDict = ["text": messageTextField.text ?? ""]
WCSession.default().sendMessage(applicationDict,
replyHandler: { replyDict in print(replyDict) },
errorHandler: { error in print(error.localizedDescription)})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment