Latest 0.3.0
Homepage https://github.com/lexrus/MMDB-Swift
License APACHE 2.0
Platforms ios 8.0, osx 10.10, requires ARC
Frameworks Foundation
Authors

Language
Version
Carthage Compatible
SPM Compatible
Platform

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.

CocoaPods

MMDB-Swift is available through CocoaPods. To install it, simply add the following line to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod "MMDB-Swift"

Then, run the following command:

pod install

Carthage

To integrate MMDB-Swift into your Xcode project using Carthage, add the following line to your Cartfile:

github "lexrus/MMDB-Swift"

Run carthage update to build the frameworks and drag the built MMDB.framework into your Xcode project.

Swift Package Manager

Package.swift

import PackageDescription

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

Usage

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

This outputs:

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

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]()
  ...
}

Author

Lex Tang (Twitter: @lexrus)

License

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.

Latest podspec

{
    "name": "MMDB-Swift",
    "version": "0.3.0",
    "summary": "A wrapper for MaxMind DB",
    "description": "A tiny wrapper for libmaxminddb which allows you to lookupnGeo data by IP address.",
    "homepage": "https://github.com/lexrus/MMDB-Swift",
    "license": {
        "type": "APACHE 2.0",
        "file": "LICENSE"
    },
    "authors": {
        "Lex Tang": "[email protected]"
    },
    "social_media_url": "https://twitter.com/lexrus",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    },
    "source": {
        "git": "https://github.com/lexrus/MMDB-Swift.git",
        "tag": "0.3.0"
    },
    "source_files": [
        "Sources/MMDB.swift",
        "Sources/libmaxminddb/maxminddb*.{h,c}"
    ],
    "ios": {
        "public_header_files": [
            "Sources/libmaxminddb/maxminddb*.h",
            "Sources/MMDB.h"
        ]
    },
    "osx": {
        "public_header_files": [
            "Sources/libmaxminddb/maxminddb*.h",
            "Sources/MMDB.h"
        ]
    },
    "prepare_command": "./update_database.sh",
    "resources": "Sources/libmaxminddb/GeoLite2-Country.mmdb",
    "frameworks": "Foundation",
    "requires_arc": true
}

Pin It on Pinterest

Share This