-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support using Realm in Swift Playgrounds #938
Comments
Did you also try to add a property in the class? On Mon, Sep 29, 2014 at 10:19 AM, Leon Breedt notifications@github.com
|
Yes, I started out with the sample from realm.io: class Dog: RLMObject {
dynamic var name = ""
dynamic var age = 0
} |
You're right this is full of sharp edges 😎. From the stack trace, it looks like there are issues with Swift's mirroring API, which is odd because we stopped using that directly a while back, though I'm sure the Swift standard library uses it somewhere. I'd say please make sure you're running in an iOS Playground and you're importing the iOS version of Realm, as your version of Xcode doesn't support OSX Playgrounds. Though my guess is that it's something in the way Realm works that's preventing it from running. Hopefully we get a chance to troubleshoot this in the near future. Until then, please update us with any progress. |
For me Realm works in a playground, building 691ef1e from source. A few notes: My playground is an iOS Playground, and my schema is NOT defined directly in my playground as @bitserf tried, rather it is defined as a framework that I made, which I then import into the playground. However, I have the caveat that I can only load a Realm database in read only mode. If I set readOnly to false, I get the error:
Note that I am loading the Realm file from the Playground's resource directory. I'm not sure how much not being able to write to the Realm is an issue with Realm, or a restriction with Playgrounds. |
Update: I changed reading from the Playground resources to: let path : String = (NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true)[0] as String).stringByAppendingPathComponent("realm.realm") and now I can open the Realm file in writable mode. |
How did you guys to it to import, mine is failing on
I'm on Xcode7 right now... Added Realm with CocoaPods:
|
I found I could CRUD Realm databases within a playground by building 17972cb from source, placing the project file into a workspace, adding a playground and creating the realm in the 'Shared Playground Data' folder.
However, I then placed the realm database file and the required classes into a framework, with Using playgrounds with Realm is fabulously useful. I hope this becomes a supported scenario. I've created all my realms this way. Would love to distribute in a framework for REPL exploration of the data... 👍 |
Realm works fabulously for me in a Playground both in-memory and on disc with the default configuration. I just crated a workspace with a playground and included RealmSwift 0.98.3 via Cocoapods by doing |
@icanzilb this works for me too. I haven't analysed the conditions for success and still get scary looking warnings in the console, but REPL-oriented development is definitely possible with Realm ! |
@DanielAsher do you get any particular error reported? I have just this in the console, which looks like nothing serious:
|
@icanzilb - yes, this is (scary but harmless) error message I get. Realm REPL remains awesome. |
ok it looks like there are subtle differences between running in a playground and in an app. This code works in an app but crashes in a Playground: let wife = Person()
let husband = Person()
husband.spouse = wife
wife.spouse = husband
try! realm.write {
realm.add(husband)
} While this code works in both an app and a Playground: let wife = Person()
let husband = Person()
husband.spouse = wife
try! realm.write {
realm.add(husband)
}
try! realm.write {
wife.spouse = husband
} I'm sure this will give a good hint if anyone's to fix this |
At present there might be more issues than I initially hoped for - trying to delete any objects also ends with SIGABRT. That's a pitty having realm in a playground could've been a real game changer |
Ok - got help and turns out both above issues were my own fault. So far I have zero issues running in a playground |
As best we can tell, Realm Swift is very usable in Xcode Playgrounds, and we're adding an example in #3370. We just forgot to update this issue whenever this was resolved, likely many months ago 😱. |
Hi,
I realise this is probably full of sharp edges, but I thought I'd try to use Realm in a playground (git HEAD, commit 2990f07). I'm on Xcode 6.0.1 GM (6A317).
I followed the instructions for getting started with Swift, and Realm is visible to my Swift application.
I can also import it into my playground, and the code completion works 😎
This is the code in the playground:
But the final let statement crashes, clicking the inspect button shows this call stack 😱
It is unclear whether it's a bug in Swift, the playground infrastructure, or something Realm does. Regardless, it would be pretty sweet to have playground support for rapid prototyping, so I just thought I'd put this up here.
Leon
The text was updated successfully, but these errors were encountered: