xcode - Using Swift with an OS X Preference Pane plugin -


i'd use swift build os x preference pane plugin system preferences app, can't work.

enter image description here

after clicking "next" xcode template doesn't offer option choose swift language, automatically creates project in objective-c.

enter image description here

without adding code or doing else, project builds successfully. if right-click on product , select "open in external editor", system preferences install , load preference pane.

enter image description here

enter image description here

enter image description here

it works!

well that's great, now, want add new cocoa subclass using swift.

enter image description here

enter image description here

accepting default, , allowing create bridging header.

enter image description here

now, quit system preferences , without adding code, rebuild project. before, right-click product , "open in external editor".

system preferences confirm replacing preference pane, , install it, fails load.

enter image description here

enter image description here

if show built product in finder, in addition .prefpane plugin, there's .swiftmodule folder.

enter image description here

i'm guessing there's missing in build phases or build settings that's responsible incorporating .swiftmodule rest of bundle, haven't been able figure out.

after add code uses new class, it's necessary import swift project umbrella header ("prax-swift.h") make project compile, importing umbrella header doesn't fix problem.

//  prax.h  #import <preferencepanes/preferencepanes.h> #import "prax-swift.h"  @interface prax : nspreferencepane  @property praxobject *ourprax;  - (void)mainviewdidload;  @end 

i tried deleting prax.h , prax.m , implementing nspreferencepane subclass in swift. before, project builds , installs, system preferences fails load it.

//  prax.swift  import preferencepanes  class prax: nspreferencepane {      override func mainviewdidload() {      } } 

sorry if i've used many pictures in question; seemed clearest way explain problem , make easy reproduce. there's simple solution. ideas?

first, need enable "embedded content contains swift" setting xcode copy necessary swift libraries bundle.

then, error:

 system preferences[68872]: dlopen_preflight failed   dlopen_preflight(/.../preftest.prefpane/contents/macos/preftest):    library not loaded: @rpath/libswiftappkit.dylib     referenced from: /.../preftest.prefpane/contents/macos/preftest       reason: image not found /.../preftest.prefpane 

this means app doesn't know load included swift libraries from.

to fix this, add @loader_path/../frameworks runpath search paths in build settings, telling swift libraries in frameworks directory of prefpane:

see dyld man page further info dynamic loading.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -