@@ -177,9 +177,73 @@ To add individual support support for other languages (of all territory names),
177177
178178The list of support languages may grow over time.
179179
180+ ## Using the C Library in an Xcode iOS Swift project
181+
182+ You can use this C library in an iOS application, built with Swift in Xcode, fairly easily.
183+ All you need to do is:
184+
185+ First, copy the directory ` mapcodelib ` to the source directory of your iOS application.
186+
187+ Then, add a text file called ` module.modulemap ` in the directory ` mapcodelib ` to export all symbols
188+ from the C library to Swift (note that ` #defines ` are not exported):
189+
190+ ```
191+ module mapcodelib [system][extern_c]{
192+ header "mapcode_alphabets.h"
193+ header "mapcode_territories.h"
194+ header "mapcoder.h"
195+ export *
196+ }
197+ ```
198+
199+ Now, you can access the C library methods like this in a Swift project:
200+
201+ ```
202+ // Example of decoding a full mapcode to a lat/lon:
203+ let territory = getTerritoryCode(context, TERRITORY_NONE)
204+ var lat: Double = 0.0
205+ var lon: Double = 0.0
206+ let mapcodeError = decodeMapcodeToLatLonUtf8(&lat, &lon, fullMapcode, territory, nil)
207+ if mapcodeError == ERR_OK {
208+ // Use the decoded lat and lon.
209+ } else {
210+ // Something went wrong decoding the full mapcode string.
211+ }
212+ ```
213+ Or encode a latitude, longitude pair to a set of Mapcodes like this:
214+
215+ ```
216+ let buffer = UnsafeMutablePointer<Int8>.allocate(capacity: Int(_MAX_MAPCODE_RESULT_ASCII_LEN))
217+ buffer.initialize(to: 0, count: Int(_MAX_MAPCODE_RESULT_ASCII_LEN))
218+ var total: Int32 = 0;
219+ var i: Int32 = 0
220+ repeat {
221+ total = encodeLatLonToSelectedMapcode(buffer, lat, lon, TERRITORY_NONE, 0, i)
222+ if (total > 0) {
223+ let mapcode = String.init(cString: buffer);
224+ }
225+ i = i + 1
226+ } while (i < total)
227+ ```
228+
229+ Or get a territory name like this:
230+
231+ ```
232+ let buffer = UnsafeMutablePointer<CChar>.allocate(capacity: Int(MAX_TERRITORY_FULLNAME_UTF8_LEN + 1))
233+ buffer.initialize(to: 0, count: Int(_MAX_TERRITORY_FULLNAME_UTF8_LEN + 1))
234+
235+ // Get alpha code.
236+ getTerritoryIsoName(buffer, TERRITORY_NLD, 0)
237+ let alphaCode = String.init(cString: buffer)
238+
239+ // Get full name.
240+ getFullTerritoryNameEnglish(buffer, TERRITORY_NLD, 0)
241+ let fullName = String.init(cString: buffer)
242+ ```
243+
180244## Release Notes
181245
182- ### 2.5.4
246+ ### 2.5.4 - 2.5.5
183247
184248* Added ` encodeLatLonToSelectedMapcode ` as a convenience for languages that use the
185249C library, but have difficulties dealing with multi-dimensional arrays (like Swift).
0 commit comments