From ecb0dab302b5ed57aa799d6ea35fb7b2714abc76 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Sat, 1 Oct 2016 00:08:21 +0100 Subject: [PATCH] Updated for 1.3 release --- CountryPicker.podspec.json | 15 ++-- .../contents.xcworkspacedata | 7 ++ CountryPicker/CountryPicker.h | 59 +++++++++---- CountryPicker/CountryPicker.m | 32 ++++--- .../project.pbxproj | 11 ++- .../contents.xcworkspacedata | 7 ++ Examples/CountryPickerDemo/AppDelegate.m | 2 +- .../CountryPickerDemo-Info.plist | 2 +- LICENCE.md | 2 +- README.md | 83 ++++--------------- 10 files changed, 112 insertions(+), 108 deletions(-) create mode 100644 CountryPicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/CountryPicker.podspec.json b/CountryPicker.podspec.json index 038e4ec4..b29bf5de 100644 --- a/CountryPicker.podspec.json +++ b/CountryPicker.podspec.json @@ -1,18 +1,19 @@ { "name": "CountryPicker", - "version": "1.2.3", - "license": "zlib", + "version": "1.3", + "license": { + "type": "zlib", + "file": "LICENCE.md" + }, "summary": "CountryPicker is a custom UIPickerView subclass that provides an iOS control allowing a user to select a country from a list.", "homepage": "http://github.com/nicklockwood/CountryPicker", - "authors": { - "Nick Lockwood": "http://charcoaldesign.co.uk/" - }, + "authors": "Nick Lockwood", "source": { "git": "https://github.com/nicklockwood/CountryPicker.git", - "tag": "1.2.3" + "tag": "1.3" }, "platforms": { - "ios": "4.3" + "ios": "5.0" }, "source_files": "CountryPicker/CountryPicker.{h,m}", "resources": "CountryPicker/CountryPicker.bundle", diff --git a/CountryPicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/CountryPicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/CountryPicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/CountryPicker/CountryPicker.h b/CountryPicker/CountryPicker.h index 9967b230..b7f36a40 100644 --- a/CountryPicker/CountryPicker.h +++ b/CountryPicker/CountryPicker.h @@ -1,10 +1,10 @@ // // CountryPicker.h // -// Version 1.2.3 +// Version 1.3 // // Created by Nick Lockwood on 25/04/2011. -// Copyright 2011 Charcoal Design +// Copyright © 2011 Nick Lockwood. All rights reserved. // // Distributed under the permissive zlib License // Get the latest version from here: @@ -35,16 +35,6 @@ // 3. This notice may not be removed or altered from any source distribution. // - -#import -#undef weak_delegate -#if __has_feature(objc_arc_weak) -#define weak_delegate weak -#else -#define weak_delegate unsafe_unretained -#endif - - #import @@ -53,6 +43,7 @@ @protocol CountryPickerDelegate +/// This method is called whenever a country is selected in the picker. - (void)countryPicker:(CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code; @end @@ -60,21 +51,53 @@ @interface CountryPicker : UIPickerView -+ (NSArray *)countryNames; -+ (NSArray *)countryCodes; -+ (NSDictionary *)countryNamesByCode; -+ (NSDictionary *)countryCodesByName; +/// Returns an array of all country names in alphabetical order. ++ (NSArray *)countryNames; + +/// Returns an array of all country codes. The codes are sorted by country +/// name, and their indices match the indices of their respective country name +/// in the `countryNames`list, but note that this means that the codes +/// themselves are not sorted alphabetically. ++ (NSArray *)countryCodes; + +/// Returns a dictionary of country names, keyed by country code. ++ (NSDictionary *)countryNamesByCode; -@property (nonatomic, weak_delegate) id delegate; +/// Returns a dictionary of country codes, keyed by country name. ++ (NSDictionary *)countryCodesByName; +/// The delegate. This implements the CountryPickerDelegate protocol, +/// and is notified when a country is selected. +@property (nonatomic, weak) id delegate; + +/// The currently selected country name. This is a read-write property, +/// so it can be used to set the picker value. Setting the picker to a country +/// name that does not appear in the `countryNames` array has no effect. @property (nonatomic, copy) NSString *selectedCountryName; + +/// The currently selected country code. This is a read-write property, so it +/// can be used to set the picker value. Setting the picker to a country code +/// that does not appear in the `countryCodes` array has no effect. @property (nonatomic, copy) NSString *selectedCountryCode; + +/// This is a convenience property to set/get the selected country using a +/// locale. The picker will automatically select the correct country based on +/// the local. To default the picker to the current device locale, you can say +/// `picker.selectedLocale = [NSLocale currentLocale];` @property (nonatomic, copy) NSLocale *selectedLocale; -@property (nonatomic, strong) UIFont *labelFont; +/// The font used by the labels in the picker. Set this to change the font. +@property (nonatomic, copy) UIFont *labelFont; +/// These method allows you to set the current country code. +/// It works exactly like the equivalent property setter, but has an optional +/// animated parameter to make the picker scroll smoothly to the selected country. - (void)setSelectedCountryCode:(NSString *)countryCode animated:(BOOL)animated; + +/// As above, but for the selected country name. - (void)setSelectedCountryName:(NSString *)countryName animated:(BOOL)animated; + +/// As above but for the selected locale. - (void)setSelectedLocale:(NSLocale *)locale animated:(BOOL)animated; @end diff --git a/CountryPicker/CountryPicker.m b/CountryPicker/CountryPicker.m index db484b88..11a7b278 100644 --- a/CountryPicker/CountryPicker.m +++ b/CountryPicker/CountryPicker.m @@ -1,10 +1,10 @@ // // CountryPicker.m // -// Version 1.2.3 +// Version 1.3 // // Created by Nick Lockwood on 25/04/2011. -// Copyright 2011 Charcoal Design +// Copyright © 2011 Nick Lockwood. All rights reserved. // // Distributed under the permissive zlib License // Get the latest version from here: @@ -37,9 +37,8 @@ #import "CountryPicker.h" - -#pragma GCC diagnostic ignored "-Wselector" -#pragma GCC diagnostic ignored "-Wgnu" +#pragma clang diagnostic ignored "-Wselector" +#pragma clang diagnostic ignored "-Wgnu" #import @@ -55,15 +54,15 @@ @interface CountryPicker () @implementation CountryPicker -//doesn't use _ prefix to avoid name clash with superclass -@synthesize delegate; +// delegate doesn't use _ prefix to avoid name clash with superclass +@synthesize delegate, labelFont = _labelFont; + (NSArray *)countryNames { static NSArray *_countryNames = nil; if (!_countryNames) { - _countryNames = [[[[self countryNamesByCode] allValues] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] copy]; + _countryNames = [[[self countryNamesByCode].allValues sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] copy]; } return _countryNames; } @@ -207,6 +206,12 @@ - (NSLocale *)selectedLocale return nil; } +- (void)setLabelFont:(UIFont *)labelFont +{ + _labelFont = labelFont; + [self reloadComponent:0]; +} + #pragma mark - #pragma mark UIPicker @@ -217,7 +222,7 @@ - (NSInteger)numberOfComponentsInPickerView:(__unused UIPickerView *)pickerView - (NSInteger)pickerView:(__unused UIPickerView *)pickerView numberOfRowsInComponent:(__unused NSInteger)component { - return (NSInteger)[[[self class] countryCodes] count]; + return (NSInteger)[[self class] countryCodes].count; } - (UIView *)pickerView:(__unused UIPickerView *)pickerView viewForRow:(NSInteger)row @@ -230,7 +235,8 @@ - (UIView *)pickerView:(__unused UIPickerView *)pickerView viewForRow:(NSInteger UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(35, 3, 245, 24)]; label.backgroundColor = [UIColor clearColor]; label.tag = 1; - if (self.labelFont) { + if (self.labelFont) + { label.font = self.labelFont; } [view addSubview:label]; @@ -245,12 +251,14 @@ - (UIView *)pickerView:(__unused UIPickerView *)pickerView viewForRow:(NSInteger NSString *imagePath = [NSString stringWithFormat:@"CountryPicker.bundle/%@", [[self class] countryCodes][(NSUInteger) row]]; UIImage *image; if ([[UIImage class] respondsToSelector:@selector(imageNamed:inBundle:compatibleWithTraitCollection:)]) + { image = [UIImage imageNamed:imagePath inBundle:[NSBundle bundleForClass:[CountryPicker class]] compatibleWithTraitCollection:nil]; + } else + { image = [UIImage imageNamed:imagePath]; + } ((UIImageView *)[view viewWithTag:2]).image = image; - - return view; } diff --git a/Examples/CountryPickerDemo.xcodeproj/project.pbxproj b/Examples/CountryPickerDemo.xcodeproj/project.pbxproj index 2537ce64..bf9bf0d8 100644 --- a/Examples/CountryPickerDemo.xcodeproj/project.pbxproj +++ b/Examples/CountryPickerDemo.xcodeproj/project.pbxproj @@ -142,7 +142,7 @@ 01D39FA514E60FBB002FC9B1 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0600; + LastUpgradeCheck = 0800; }; buildConfigurationList = 01D39FA814E60FBB002FC9B1 /* Build configuration list for PBXProject "CountryPickerDemo" */; compatibilityVersion = "Xcode 3.2"; @@ -227,6 +227,7 @@ CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES; CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; @@ -235,14 +236,17 @@ CLANG_WARN_OBJC_RECEIVER_WEAK = YES; CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES; CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -300,6 +304,7 @@ CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES; CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; @@ -308,6 +313,7 @@ CLANG_WARN_OBJC_RECEIVER_WEAK = YES; CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES; CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES; @@ -315,6 +321,7 @@ COPY_PHASE_STRIP = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_SHORT_ENUMS = YES; GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES; @@ -355,6 +362,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_TREAT_WARNINGS_AS_ERRORS = YES; INFOPLIST_FILE = "CountryPickerDemo/CountryPickerDemo-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WARNING_CFLAGS = ( "-Wall", @@ -370,6 +378,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_TREAT_WARNINGS_AS_ERRORS = YES; INFOPLIST_FILE = "CountryPickerDemo/CountryPickerDemo-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WARNING_CFLAGS = ( "-Wall", diff --git a/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/Examples/CountryPickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Examples/CountryPickerDemo/AppDelegate.m b/Examples/CountryPickerDemo/AppDelegate.m index 19b7bc6a..69c487b1 100644 --- a/Examples/CountryPickerDemo/AppDelegate.m +++ b/Examples/CountryPickerDemo/AppDelegate.m @@ -16,7 +16,7 @@ @implementation AppDelegate - (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWithOptions:(__unused NSDictionary *)launchOptions { - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; // Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.window.rootViewController = self.viewController; diff --git a/Examples/CountryPickerDemo/CountryPickerDemo-Info.plist b/Examples/CountryPickerDemo/CountryPickerDemo-Info.plist index a09e3313..5da589db 100644 --- a/Examples/CountryPickerDemo/CountryPickerDemo-Info.plist +++ b/Examples/CountryPickerDemo/CountryPickerDemo-Info.plist @@ -11,7 +11,7 @@ CFBundleIconFiles CFBundleIdentifier - com.charcoaldesign.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/LICENCE.md b/LICENCE.md index d0f58adc..856270fc 100755 --- a/LICENCE.md +++ b/LICENCE.md @@ -1,6 +1,6 @@ CountryPicker -Version 1.2.3, December 4th, 2014 +Version 1.3, September 30th, 2016 Copyright (C) 2011 Charcoal Design diff --git a/README.md b/README.md index 7e94bfec..0e395e5f 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +[![License](https://img.shields.io/badge/license-zlib-lightgrey.svg?maxAge=2592000)](https://opensource.org/licenses/Zlib) +[![CocoaPods](https://img.shields.io/cocoapods/p/CountryPicker.svg?maxAge=2592000)](https://cocoapods.org/pods/CountryPicker) +[![CocoaPods](https://img.shields.io/cocoapods/metrics/doc-percent/CountryPicker.svg?maxAge=2592000)](http://cocoadocs.org/docsets/CountryPicker/) +[![Twitter](https://img.shields.io/badge/twitter-@nicklockwood-blue.svg?maxAge=2592000)](http://twitter.com/nicklockwood) + ![Screenshot](Examples/CountryPicker.png) Purpose @@ -11,9 +16,9 @@ Note that the list of countries is based on the ISO 3166 country code standard ( Supported iOS & SDK Versions ----------------------------- -* Supported build target - iOS 8.1 (Xcode 6.1, Apple LLVM compiler 6.0) +* Supported build target - iOS 10.0 (Xcode 8.0, Apple LLVM compiler 8.0) * Earliest supported deployment target - iOS 6.0 -* Earliest compatible deployment target - iOS 4.3 +* Earliest compatible deployment target - iOS 5.0 NOTE: 'Supported' means that the library has been tested with this version. 'Compatible' means that the library should work on this iOS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly. @@ -31,71 +36,7 @@ Installation To use the CountryPicker in an app, just drag the CountryPicker class files into your project. If you want to use the flag icons, drag the CountryPicker.bundle folder in also. - -CountryPicker class methods ------------------------------ - -The CountryPicker class includes several handy methods for retrieving country names and codes, and converting between the two: - - + (NSArray *)countryNames; - -Returns an array of all country names in alphabetical order. - - + (NSArray *)countryCodes; - -Returns an array of all country codes. The codes are sorted by country name, and their indices match the indices of their respective country name in the `countryNames` list, but note that this means that the codes themselves are not sorted alphabetically. - - + (NSDictionary *)countryNamesByCode; - -Returns a dictionary of country names, keyed by country code. - - + (NSDictionary *)countryCodesByName; - -Returns a dictionary of country codes, keyed by country name. - - -CountryPicker properties ---------------------------- - -Each CountryPicker view has the following properties: - - @property (nonatomic, assign) id delegate; - -The delegate. This implements the CountryPickerDelegate protocol, and is notified when a country is selected. - - @property (nonatomic, copy) NSString *selectedCountryName; - -The currently selected country name. This is a read-write property, so it can be used to set the picker value. Setting the picker to a country name that does not appear in the `countryNames` array has no effect. - - @property (nonatomic, copy) NSString *selectedCountryCode; - -The currently selected country code. This is a read-write property, so it can be used to set the picker value. Setting the picker to a country code that does not appear in the `countryCodes` array has no effect. - - @property (nonatomic, copy) NSLocale *selectedLocale; - -This is a convenience property to set/get the selected country using a locale. The picker will automatically select the correct country based on the local. To default the picker to the current device locale, you can say: - - picker.selectedLocale = [NSLocale currentLocale]; - - -CountryPicker instance methods ----------------------------------- - - - (void)setSelectedCountryCode:(NSString *)countryCode animated:(BOOL)animated; - - (void)setSelectedCountryName:(NSString *)countryName animated:(BOOL)animated; - - (void)setSelectedLocale:(NSLocale *)locale animated:(BOOL)animated; - -These methods allow you to set the current country via name, code or locale. THey work excatly like the equivalent property setters, but have an optional animated parameter to make the picker scroll smoothly to the selected country. - - -CountryPickerDelegate protocol --------------------------------- - -The CountryPickerDelegate protocol has a single obligatory method: - - - (void)countryPicker:(CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code; - -This method is called whenever a country is selected in the picker. +Alternatively, you can install CountryPicker using Cocoapods or Carthage, Subclassing @@ -111,6 +52,14 @@ To change the display order, or display duplicate copies of (say) US or UK at th Release notes ------------------ +Version 1.3 + +- Updated project for Xcode 8 +- You can now override the font used by the picker labels +- Country sorting is now correct for localized names +- Flag images are now loaded from the correct bundle +- Added Carthage support + Version 1.2.3 - Moved flag images into a resource bundle