Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kmikael committed Jul 18, 2016
0 parents commit cd45462
Show file tree
Hide file tree
Showing 525 changed files with 6,979 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 kWallet GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions Planet.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Pod::Spec.new do |s|
s.name = 'Planet'
s.version = '0.1.0'
s.summary = 'A country picker'
s.description = 'A country picker view controller'
s.homepage = 'https://github.com/kwallet/planet'

s.license = 'MIT'

s.author = {'Mikael Konutgan' => 'mikael@k-wallet.com'}

s.source = {git: 'https://github.com/kwallet/planet', tag: s.version}

s.platform = :ios, '9.3'

s.source_files = "Planet", 'Classes/**/*.{h,m,swift}'
s.resources = 'Planet/Planet.xcassets'
end
589 changes: 589 additions & 0 deletions Planet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Planet.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions Planet.xcodeproj/xcshareddata/xcschemes/Planet.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C2C1D37EECD00D836C4"
BuildableName = "Planet.framework"
BlueprintName = "Planet"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C361D37EECD00D836C4"
BuildableName = "PlanetTests.xctest"
BlueprintName = "PlanetTests"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C2C1D37EECD00D836C4"
BuildableName = "Planet.framework"
BlueprintName = "Planet"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C2C1D37EECD00D836C4"
BuildableName = "Planet.framework"
BlueprintName = "Planet"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C2C1D37EECD00D836C4"
BuildableName = "Planet.framework"
BlueprintName = "Planet"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
91 changes: 91 additions & 0 deletions Planet.xcodeproj/xcshareddata/xcschemes/PlanetExample.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C611D39103A00D836C4"
BuildableName = "PlanetExample.app"
BlueprintName = "PlanetExample"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C611D39103A00D836C4"
BuildableName = "PlanetExample.app"
BlueprintName = "PlanetExample"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C611D39103A00D836C4"
BuildableName = "PlanetExample.app"
BlueprintName = "PlanetExample"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "64585C611D39103A00D836C4"
BuildableName = "PlanetExample.app"
BlueprintName = "PlanetExample"
ReferencedContainer = "container:Planet.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
24 changes: 24 additions & 0 deletions Planet/Country.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Country.swift
// Planet
//
// Created by Mikael Konutgan on 15/07/16.
// Copyright © 2016 kWallet GmbH. All rights reserved.
//

import UIKit

public struct Country {
public let name: String
public let isoCode: String
public let callingCode: String
}

public extension Country {
var image: UIImage? {
let imageName = isoCode
let bundle = NSBundle.planetBundle()

return UIImage(named: imageName, inBundle: bundle, compatibleWithTraitCollection: nil)
}
}
68 changes: 68 additions & 0 deletions Planet/CountryDataSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// CountryDataSource.swift
// Planet
//
// Created by Mikael Konutgan on 15/07/16.
// Copyright © 2016 kWallet GmbH. All rights reserved.
//

import Foundation

class CountryDataSource {
let currentCountry: Country?

private let countries: [[Country]]

init(locale: NSLocale = .currentLocale()) {
let countryCodes = NSLocale.ISOCountryCodes()

let dataAsset = NSDataAsset(name: "country-calling-codes", bundle: .planetBundle())!
let callingCodes = (try? NSJSONSerialization.JSONObjectWithData(dataAsset.data, options: [])) as! [String: String]

var currentCountries: [Country] = []
var otherCountries: [Country] = []

let currentCountryCode = locale.objectForKey(NSLocaleCountryCode) as! String

for countryCode in countryCodes {
guard let countryName = locale.displayNameForKey(NSLocaleCountryCode, value: countryCode) else {
continue
}

guard let callingCode = callingCodes[countryCode] else {
continue
}

let country = Country(name: countryName, isoCode: countryCode, callingCode: "+\(callingCode)")

if country.isoCode == currentCountryCode {
currentCountries.append(country)
} else {
otherCountries.append(country)
}
}

otherCountries.sortInPlace { $0.name.localizedCaseInsensitiveCompare($1.name) == .OrderedAscending }

currentCountry = currentCountries.first
countries = [currentCountries, otherCountries]
}

func sectionCount() -> Int {
return countries.count
}

func count(section: Int) -> Int {
return countries[section].count
}

func find(indexPath: NSIndexPath) -> Country {
return countries[indexPath.section][indexPath.row]
}

func find(text: String) -> [Country] {
return countries.flatten()
.filter { $0.name.localizedCaseInsensitiveContainsString(text) }
.sort { $0.name.localizedCaseInsensitiveCompare($1.name) == .OrderedAscending }
}
}
Loading

0 comments on commit cd45462

Please sign in to comment.