3

The Swift integration of a new Realm-DB (realm 0.92.3) under Xcode 6.3 and iOS10.10.3 basically works for the iPhone (not for the Apple-Watch yet). The integration of the same realm-framework under Watchkit (i.e. Apple-Watch) does not work yet.

The RealmSwift.framework is integrated (dragged into) the Embedded-Binaries as described here1 and here2. See screenshot below :

enter image description here

When running the Watchkit-App with the simulator the following error occurs :

dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /Users/XXX/Library/Developer/CoreSimulator/Devices/3FE99-9-4C4C2/data/Containers/Bundle/Application/8B4-DF19F34-222973/MyApp.app/PlugIns/MyApp WatchKit Extension.appex/MyApp WatchKit Extension
  Reason: image not found
(lldb) 

What is still wrong ???

The Framework-Search-Path of the main-app is set. The ones for MyApp Watchkit Extension and MyApp Watchkit App are not set. Setting them does not change the above error. What is still missing ???

Community
  • 1
  • 1
iKK
  • 6,394
  • 10
  • 58
  • 131
  • Do you have any swift files in your App Extension / main app? If not, `swift-stdlib-tool` won't copy over the swift runtime dylibs, even if you have a framework that requires them. – segiddins May 15 '15 at 22:32
  • Yes, I do have swift-files in both (i.e. App Extension and main-app) – iKK May 15 '15 at 22:38
  • I finally found a solution: Start over again with a new project (identical bundle-name) and copy all relevant storyboard- swiftFiles, frameworks, etc etc from a previously made project-copy step-by-step into the new project. That way, my watchKit starts working with the simulator ! It is, at least, unfortunate not to know what exactly was missing before ! – iKK May 15 '15 at 22:41

2 Answers2

2

I would recommend that you use CocoaPods.

I did it like you did, with dynamic frameworks, but when I try to submit my application to iTunes Connect using Xcode's Organizer, I could not because of the nested frameworks. Realm.framework is inside RealmSwift.framework, and that is not okay with Apple. So I try and try but nothing helped…

Then I used CocoaPods and everything worked as it should.

Here are instructions for CocoaPods installation:

Install CocoaPods 0.37.1 or later ([sudo] gem install cocoapods).
In your Podfile, add use_frameworks! and pod 'RealmSwift' to your main and test targets.
From the command line, run pod install.
Use the .xcworkspace file generated by CocoaPods to work on your project!
bdash
  • 18,110
  • 1
  • 59
  • 91
TomazStoiljkovic
  • 808
  • 8
  • 21
  • Thank you very much, Kruherson ! That is a great help. I will have a look at CocoaPods like you recommended. – iKK May 20 '15 at 18:35
  • Just another question: Having done the CocoaPods installation and opening the resulting MyApp.xcworkspace, it all seems to work, except: The "import RealmSwift" is no longer working. What do I need to place instead ?? – iKK May 24 '15 at 16:17
  • You don't need to import RealmSwift anymore :) – TomazStoiljkovic May 24 '15 at 19:03
  • If I comment-out all the "import RealmSwift" then I get plenty of errors (i.e. any realm-code is not recognized, such as for example Object, Realm, NotificationToken etc). Can you please tell me how your Podfile looked like ? And also how your MyApp-Bridging-Header.h file looked like ? And maybe also if I have to add all the new Pods-MyApp-xy schemas that seem to be there?? Not sure how I can make this get to work... – iKK May 24 '15 at 19:15
  • Do I still need to import any RealmFramework after having done the "pod install" ?? – iKK May 24 '15 at 19:18
  • I added the "import RealmSwift" again and now it is working with the cocoapods !! It seems that my 'swift-file with the realm-object definition' needs the "import RealmSwift" since it is used in two locations, 1. in the "MyApp" and 2. in the "MyApp WatchKit Extension". The second one I never got to work without the "import" statement. Do you have any other suggestion ?? – iKK May 25 '15 at 10:18
  • I am using Realm only on iPhone app, not in WatchKit Extension app. When I need something from database I call "handleWatchKitExtensionRequest" in iPhone app and send back a reply to watch. I Didn't try using Realm directly on WatchKit Extension app. – TomazStoiljkovic May 25 '15 at 10:55
  • Thank you Kruherson! Ahh, that explains it. You are right, only iPhone-App plus Realm (doing it with Cocoapods) does not seem to need the "import RealmSwift". However, I could not get it to work without it as for the MyApp WatchKit Extension.... Do you know why by chance ? – iKK May 25 '15 at 11:00
1

This Podfile finally did it for me (see below). Everything worked after that... To install just open a terminal, go to your App's folder (where you place the Podfile) and type

pod install

After that make sure to open from now on the "MyApp.xcworkspace" (no longer "MyApp.xcodeproj") and you are all set !

Here is the podfile that worked :

xcodeproj 'MyApp.xcodeproj'
workspace 'MyApp.xcworkspace'
platform :ios, '8.3'

source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!
link_with 'MyApp', 'MyApp WatchKit Extension'

def shared_pods
      pod 'RealmSwift', '>= 0.93.2'
end

target 'MyApp' do
    shared_pods
end

target 'MyAppTests' do
    shared_pods
end

target 'MyApp WatchKit Extension' do
    shared_pods
end
S1LENT WARRIOR
  • 11,704
  • 4
  • 46
  • 60
iKK
  • 6,394
  • 10
  • 58
  • 131