A tiny wrapper for libmaxminddb which allows you to lookup Geo data by IP address.

This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com.

Swift Package Manager

Install Swift Package Manager. Edit your Package.swift file:

import PackageDescription

let package = Package(
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/lexrus/MMDB-Swift", versions: "0.0.1" ..< Version.max)


guard let db = MMDB() else {
  print("Failed to open DB.")
if let country = db.lookup("") {

This outputs:

  "continent": {
    "code": "NA",
    "names": {
      "ja: "北アメリカ",
      "en: "North America",
      "ru: "Северная Америка",
      "es: "Norteamérica",
      "pt-BR: "América do Norte",
      "de: "Nordamerika",
      "zh-CN: "北美洲",
      "fr: "Amérique du Nord"
  "isoCode": "US",
  "names": {
    "ja: "アメリカ合衆国",
    "en: "United States",
    "ru: "США",
    "es: "Estados Unidos",
    "pt-BR: "Estados Unidos",
    "de: "USA",
    "zh-CN: "美国",
    "fr: "États-Unis"

Notice that country is a struct defined as:

public struct MMDBContinent {
    var code: String?
    var names: [String: String]?

public struct MMDBCountry: CustomStringConvertible {
    var continent = MMDBContinent()
    var isoCode = ""
    var names = [String: String]()


Lex Tang (Twitter: @lexrus)


MMDB-Swift is available under the Apache License Version 2.0. See the LICENSE file for more info.

The GeoLite2 databases are distributed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.