Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

hello, i have developped an app on ios using objective-c and ultralite. (using sql anywhere 12) i am moving my programming to swift 3 now, but there's no way to add c++ modules into a swift based project (even if i create a bridging header, it's not working) what should i do? any hints?

asked 29 Jan '17, 06:22

deebee's gravatar image

deebee
26112
accept rate: 0%

Also note that SQL Anywhere 12 is no longer actively maintained by engineering. It would be good to take this opportunity to switch to version 17.

(31 Jan '17, 11:18) Tim McClements

I think the best approach is to write an Objective-C++ cover for the UltraLite classes -- something that's tailored to your application needs and that also handles the conversion to/from Objective-C types. Then you can call this interface from Swift. In this way, you can definitely add C++ modules to your Swift project, you just can't call C++ directly from Swift.

permanent link

answered 30 Jan '17, 11:36

Tim%20McClements's gravatar image

Tim McClements
2.0k1830
accept rate: 35%

There are a lot of goggle hits for "call objective c from swift".

(30 Jan '17, 14:34) Breck Carter

well, there are lots of documentations about calling objective c from swift.. however, very few talk about mixed c++ and swift.. i have read some tutorials on the net, but they mainly take very primitive c++ files and create bridging headers for them... the ultralite library is actually a complete set of .h files referencing each other.. with many custom typedefs that don't match anything similar in swift or objective c. i am just asking to see if there's already anyone who's done some basic work or if there are plans to add support for swift on ios.

(31 Jan '17, 14:25) deebee
Replies hidden
1

Right - the UL headers are not trivial, but I don't think that really changes anything. You include the UL headers only in your .mm file(s) that implement the database interface you design for your app. And then you just include your interface header in the bridging header for Swift.

Your database interface may include a result-set object with methods like, say, next and stringForColumn:, or it could take a SQL statement and return an array of results in one step, or it could be less generic and directly manage application model objects that are persisted. In any case, your interface should be much simpler than the full UL C++ API.

(31 Jan '17, 16:52) Tim McClements
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×371
×162
×20

question asked: 29 Jan '17, 06:22

question was seen: 2,005 times

last updated: 31 Jan '17, 16:54