• Stars
    star
    120
  • Rank 295,268 (Top 6 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

MMDB-Swift

Language Version Carthage Compatible SPM Compatible Platform

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


NOTE From v0.5.0, MMDB-Swift no longer bundles GeoLite2 database due to the license change. Developers should download the binary version from the Maxmind website.

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("PATH_TO_THE_DATABASE") 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.

More Repositories

1

LTMorphingLabel

[EXPERIMENTAL] Graceful morphing effects for UILabel written in Swift.
Swift
7,983
star
2

VPNOn

Turn On your VPN like a hero.
Swift
4,470
star
3

fontdiao

[已废弃]中文图标字体,可用于 Web 或 iOS,同时提供了国内各种常用网站、应用的徽标 SVG 源文件。
CSS
617
star
4

ios-makefile

[DEPRECATED] The universal makefile for my iOS projects distributes IPAs in seconds
Shell
577
star
5

ios-dev-playbook

不会运维的 iOS 开发不是好设计师。这个 Ansible Playbook 能快速配置 iOS 开发需要的服务,安装如 Gogs、GitLab、Jenkins、Ghost、Ajenti 等常用服务。
Ruby
555
star
6

LTBouncyPlaceholder

A learning-by-doing UITextField extension written in Swift
Swift
490
star
7

LTJelloSwitch

A rapid prototype of UISwitch built with Swift and PaintCode.
Swift
365
star
8

LeetCode.swift

Once upon a time there was a noob of algorithms, and he knew a little about Swift.
Swift
357
star
9

LTFinderButtons

My Finder buttons collection for macOS.
Rich Text Format
305
star
10

PhoneticContacts

为你的联系人加上拼音属性,这样即使你的 iPhone 设置成英文,也能有按拼音分段的功能。暂时还没有改成用 Contacts framework,Xcode 10 无法运行哦
Swift
294
star
11

RegExPlus

A nifty RegEx test tool built with SwiftUI
Swift
203
star
12

QLSwift

A Quick Look plugin for Swift files
Objective-C
177
star
13

Huahui

。.゚✧:✿花༙྇灰༙྇✿:✧゚.。 - 灰化肥会发黑,花会化灰。又名『中国程序员常读错的英文单词的 App』
Swift
152
star
14

LTBlacklist

[DEPRECATED] The missing Blacklist app for your iOS 5/6 with private APIs. No Jailbreak Required!
Objective-C
147
star
15

SwiftyMenu

The missing Finder menu for your daily ease
Swift
128
star
16

APN

[已废弃]适合 iOS 7 的 APN 设置工具,又一个没过审核的周末项目
Objective-C
116
star
17

LTUpdate

[DEPRECATED] LeT'sUpdate to the new version available in the AppStore! A GCD powered, ARC/MRC compatible class with block interfaces.
Objective-C
75
star
18

LexClockWidget

Swift
73
star
19

KissDefault

[EXPERIMANTAL] 💋Keep It(UserDefaults propertyWrapper) Simple and Stupid
Swift
46
star
20

.files

Dotfiles for my Mac
Shell
34
star
21

HighlightJSON

A tiny Safari Web Extension for presenting highlighted JSON files
Swift
33
star
22

LTTabBar

[DEPRECATED] A clumsy mimic of the Chrome-style tab bar for iOS.
Objective-C
32
star
23

LexNightmare

A boring game built with SpriteKit and Swift.
Swift
23
star
24

HNAPI

Tiny HackerNews API wrapper.
Swift
21
star
25

iDevBox

Yet another learning-by-doing XcodeKit project
Swift
18
star
26

LTDribbbleAPI

Yet another Dribbble API client for iOS 6.0+ and Mac OS X 10.8+ based on AFNetworking 2.0.
Objective-C
12
star
27

XcodeAutomator

Automator services for Xcode
8
star
28

PixelPusher

Compare your app with the original design pixel-by-pixel.
Swift
7
star
29

ansible-role-docker

An Ansible role to install Docker in Debian or Ubuntu
6
star
30

GCD

GCD = Ghost + Caddy + Dropbox
Shell
6
star
31

ios_notebook

3
star
32

XcodeTemplates

My personal Xcode templates
3
star
33

lexrus

2
star
34

LibWebpXCDemo

Swift
1
star
35

lexrus.github.io

My personal Hugo website: https://lex.sh
SCSS
1
star