This is a sample Xcode 11 project (a nigh vanilla/default SwiftUI project) which has:
all setup including sample bridging code to enable function execution and data exchange between Swift 5 and R.
A few key things are included/set:
- Search paths:
/Library/Frameworks/R.framework/Headers/
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RInside/include/
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/
- Frameworks, Libraries and Embedded Content:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libR.dylib
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RInside/lib/libRInside.dylib
- Hardened Runtime is enabled with an entitlement of "Disable Library Validation" because the RInside and R shared libraries aren't codesigned (see
rin-swift/rin_test.entitlements
)
- one
.mm
file which lets Xcode know we're using Objective-C++. This is where you include things likeR.h
,Rcpp.h
, andRInside.h
or other C/C++ libraries - one ^^ corresponding
.hpp
file that has no imports or includes of anything R/Rcpp-ish and defines the functions you're going to expose to Swift - one bridging header (setup as as an "Objective C Bridging Header" under "Swift Compiler" in the General settings. This should just include ^^
- R (RInside) is initialized in the
AppDelegate.swift
and an example of calling functions with and without parameters is inContentView.swift
There are quite a number of post-compilation yellow flags due to the R-ish headers but it builds and runs fine.
Built on the shoulders of: