realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.32k stars 2.15k forks source link

Swift 2.0 iOS target vs Mac targets #2141

Closed jeeftor closed 9 years ago

jeeftor commented 9 years ago

as per the blog post directions its says

Go to your Xcode project’s “General” settings. Drag the versions of RealmSwift.framework and Realm.framework from build/ios-dynamic/ or osx/ directory to the “Embedded Binaries” section. Make sure Copy items if needed is selected and click Finish.

From what I can tell the iso-dynamic directly only has a copy of Realm.framework

Is there a build target for iOS RealmSwift.framework

screen shot 2015-06-30 at 2 03 57 pm

segiddins commented 9 years ago

@jeeftor both of the frameworks in the ios/swift directory are dynamic, so you can just use those! Our swift-specific docs at https://realm.io/docs/swift/latest/ have slightly different installation instructions, which should hopefully make things a bit more clear!

kevinmlong commented 9 years ago

@segiddins - so, we built the swift-2.0 branch and dropped the Realm.framework and RealmSwift.framework files into the "Embedded Frameworks" section, but still get an error that module RealmSwift cannot be found. We were using Carthage Before, but want to start doing an upgrade to 2.0. Thoughts?

jpsim commented 9 years ago

you'll need to make sure your framework search paths are set up to find these new frameworks

kevinmlong commented 9 years ago

@jpsim - excuse my ignorance, but how might we go about doing that...

kevinmlong commented 9 years ago

@jpsim and @segiddins - disregard my previous question. I figured it out. I'm now faced with "Abort trap 6" build errors for all the Realm model files. Any thoughts?

segiddins commented 9 years ago

That sounds like a swift bug, I'd recommend filing a Radar for apple at bug report.apple.com

kevinmlong commented 9 years ago

Yeah. Probably. Have y'all run into this at all?

kevinmlong commented 9 years ago

@segiddins Seems that the error is for each of the model files. Here is a snippet of the error:

CompileSwift normal x86_64 <PATH_TO_MODELS_FOLDER>/Airport.swift

Assertion failed: (hasAccessibility() && "accessibility not computed yet"), function getFormalAccess, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.42.3/src/swift/include/swift/AST/Decl.h, line 2195.

1. While emitting IR SIL function @_TFC4otto7AirportcfMS0_FT5realmCSo8RLMRealm6schemaCSo15RLMObjectSchema_S0_ for 'init' at <PATH_TO_MODELS>/Airport.swift:16:31

kevinmlong commented 9 years ago

@segiddins - this line 16 from Airport.swift

public class Airport : Object {

segiddins commented 9 years ago

I haven't seen that one yet, no!

sandalsoft commented 9 years ago

@kevinmlong I was also using Carthage for pre-Swift2.0 Realm.

  1. Follow build instructions from: https://realm.io/docs/swift/latest/#swift-20
  2. Copy the newly built Realm.framework and RealmSwift.framework files from build/ios/swift/ to [iOSPROJECT ROOT]/Carthage/Build/iOS/ directory
  3. Clean & build

No need to drag the files into the Embedded Binaries of your target. If you were using Realm with Carthage before, the carthage build script /usr/local/bin/carthage copy-frameworks will pick up the new files and make it happen. Hopefully.

jpsim commented 9 years ago

@sandalsoft Carthage doesn't actually build Realm Swift from source, so that won't work.

kevinmlong commented 9 years ago

@jpsim @sandalsoft @segiddins - I'm not sure what the issue is. I cloned and build swift-2.0 branch. I copied the Realm.framework and RealmSwift.framework files into the Carthage build directory. That all seemed fine and good and recognizes RealmSwift, but the issue is that when it builds I get Abort trap: 6 errors for each of the model files. Close inspection at the error logging shows that it is due to an assertion error:

Assertion failed: (hasAccessibility() && "accessibility not computed yet"), function getFormalAccess, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.42.3/src/swift/include/swift/AST/Decl.h, line 2195.

Seems like it's an issue with the Object class. I did a test by replacing Object with RLMObject and the error for that specific model goes away.

jpsim commented 9 years ago

I think your using a Realm Swift framework that was built before you switched to the Swift 2 branch, because like I said, Carthage won't build Realm Swift from source

kevinmlong commented 9 years ago

I know Carthage doesn't build RealmSwift from source. I just cloned and checked out realm/realm-cocoa. I switched to the branch swift-2.0. Then ran build.sh build and copy the resulting Realm.framework and RealmSwift.framework from build/ios/swift.

segiddins commented 9 years ago

Anyways @kevinmlong , if the swift compiler is crashing, that's a bug in the swift compiler -- it's probably a combination of using Realm Swift and whatever other code you have in your project. Unfortunately, there's really nothing to do about it besides filing a radar for Apple.

sandalsoft commented 9 years ago

@jpsim Correct, it doesn't build from source.... Which is why step 1 is to build it from source yourself.

ryanbillingsley commented 9 years ago

Just adding to the chorus, Xcode 7 Beta 2, cannot compile any models. I get the following:

Assertion failed: ((!FileContext || issue != Status::Malformed) && "error deserializing an individual record"), function error, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.42.3/src/swift/include/swift/Serialization/ModuleFile.h, line 348.

This could be related to this radar: http://www.openradar.me/21668238.

I built the framework from source.

Also, looking at https://realm.io/docs/swift/latest/#swift-20, the docs are confusing:

Drag the versions of RealmSwift.framework and Realm.framework from build/ios-dynamic/ or osx/ directory to the “Embedded Binaries” section.

There is no RealmSwift.framework in the is build/ios-dynamic/ directory

kevinmlong commented 9 years ago

I ended up forking and creating a dummy release with an attachment so that Carthage works.

Cartfile looks like:

github "kevinmlong\realm-cocoa" ~> 0.200.0

Works great...

jpsim commented 9 years ago

@ryanbillingsley our Swift 2.0 instructions were incorrect (should have been build/ios/swift/ rather than build/ios-dynamic), and we've updated https://realm.io/docs/swift/latest/#swift-20 to reflect that.

sandalsoft commented 9 years ago

@kevinmlong Nice! Thanks for doing that.

Just a heads up, I just tried your repo with Carthage for Xcode 7.0b3 and it's giving me this error: Module file was created by an older version of the compiler

Not surprising, just wanted to mention it.

kevinmlong commented 9 years ago

Hmm...I'm on Beta 2. Didn't know Beta 3 was out. I'll update to Beta 3 and push an update sometime tomorrow. Thanks for the updates. On Jul 8, 2015 9:42 PM, "Eric Nelson" notifications@github.com wrote:

@kevinmlong https://github.com/kevinmlong Nice! Thanks for doing that.

Just a heads up, I just tried your repo with Carthage for Xcode 7.0b3 and it's giving me this error: Module file was created by an older version of the compiler

— Reply to this email directly or view it on GitHub https://github.com/realm/realm-cocoa/issues/2141#issuecomment-119779372.

dmathewwws commented 9 years ago

@kevinmlong thanks for doing that.

Did it work for you on XCode 7 beta 3 when you tried it. I am still getting the "Module file was created by an older version of the compiler" error

I used github "kevinmlong\realm-cocoa" ~> 0.200.1 in my cartfile

kevinmlong commented 9 years ago

That's what I'm using too...hmm...

Have you tried clearing the carthage cache?

rm -rf Cartfile.resolved Carthage/ ~/Library/Caches/org.carthage.CarthageKit/

dmathewwws commented 9 years ago

thanks @kevinmlong. thats all i needed to do.