diff --git a/.gitignore b/.gitignore index 8f0d98a..fb44f2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,39 @@ -.svn -.idea -*.pyc -.project -.classpath -*.mode1v3 -*.pbxuser -*.DS_Store +# Generic files *~ +*.classpath +*.DS_Store +*.idea +*.lock +*.log +*.out +*.svn *.swp +*.project +*.pyc + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control +# +# Pods/ diff --git a/Classes/HTAutocompleteTextField.h b/Classes/HTAutocompleteTextField.h index 93281eb..16f9c66 100644 --- a/Classes/HTAutocompleteTextField.h +++ b/Classes/HTAutocompleteTextField.h @@ -8,7 +8,7 @@ // Copyright (c) 2012 Hotel Tonight. All rights reserved. // -#import +@import UIKit; @class HTAutocompleteTextField; @@ -31,24 +31,24 @@ /* * Designated programmatic initializer (also compatible with Interface Builder) */ -- (id)initWithFrame:(CGRect)frame; +- (instancetype)initWithFrame:(CGRect)frame; /* * Configure how suggestions are made */ -@property (nonatomic, assign) BOOL suggestionsDisabled; +@property (nonatomic) BOOL suggestionsDisabled; @property (nonatomic, weak) id autocompleteTextFieldDelegate; /* * Configure text field appearance */ -@property (nonatomic, strong, readonly) UILabel *suggestionLabel; -@property (nonatomic, assign) CGPoint suggestionLabelExtraPositionOffset; +@property (nonatomic, readonly) UILabel *suggestionLabel; +@property (nonatomic) CGPoint suggestionLabelExtraPositionOffset; /* * Specify a data source responsible for determining autocomplete text. */ -@property (nonatomic, strong) id suggestionDataSource; +@property (nonatomic) id suggestionDataSource; /* * Subclassing: diff --git a/Classes/HTAutocompleteTextField.m b/Classes/HTAutocompleteTextField.m index a6e25c4..d74d9f0 100644 --- a/Classes/HTAutocompleteTextField.m +++ b/Classes/HTAutocompleteTextField.m @@ -11,186 +11,182 @@ #import "HTAutocompleteTextField.h" @interface HTAutocompleteTextField () -@property (nonatomic, strong) NSString *suggestionString; -@property (nonatomic, strong, readwrite) UILabel *suggestionLabel; + +@property (nonatomic, readwrite) NSString *suggestionString; +@property (nonatomic, readwrite) UILabel *suggestionLabel; + +- (CGRect)suggestionLabelRectForBounds:(CGRect)bounds; +- (void)ht_textDidChangeNotificationFired:(NSNotification *)notification; +- (void)updateSuggestionLabel; +- (void)refreshSuggestionText; +- (void)acceptSuggestionText; + @end @implementation HTAutocompleteTextField -- (id)initWithFrame:(CGRect)frame -{ - self = [super initWithFrame:frame]; - if (self) - { - [self setupAutocompleteTextField]; - } - return self; -} +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; -- (void)awakeFromNib -{ - [super awakeFromNib]; - + if (self) { [self setupAutocompleteTextField]; + } + + return self; } -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:self]; +- (void)awakeFromNib { + [super awakeFromNib]; + + [self setupAutocompleteTextField]; } -- (void)setupAutocompleteTextField -{ - self.suggestionLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - self.suggestionLabel.font = self.font; - self.suggestionLabel.backgroundColor = [UIColor clearColor]; - self.suggestionLabel.textColor = [UIColor lightGrayColor]; - self.suggestionLabel.lineBreakMode = NSLineBreakByClipping; - self.suggestionLabel.hidden = YES; - [self addSubview:self.suggestionLabel]; - [self bringSubviewToFront:self.suggestionLabel]; +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UITextFieldTextDidChangeNotification + object:self]; +} - self.suggestionString = @""; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ht_textDidChangeNotificationFired:) name:UITextFieldTextDidChangeNotification object:self]; +- (void)setupAutocompleteTextField { + self.suggestionLabel = [[UILabel alloc] initWithFrame:CGRectZero]; + self.suggestionLabel.font = self.font; + self.suggestionLabel.backgroundColor = [UIColor clearColor]; + self.suggestionLabel.textColor = [UIColor lightGrayColor]; + self.suggestionLabel.lineBreakMode = NSLineBreakByClipping; + self.suggestionLabel.hidden = YES; + [self addSubview:self.suggestionLabel]; + [self bringSubviewToFront:self.suggestionLabel]; + + self.suggestionString = @""; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(ht_textDidChangeNotificationFired:) + name:UITextFieldTextDidChangeNotification + object:self]; } #pragma mark - Configuration +- (void)setFont:(UIFont *)font { + [super setFont:font]; -- (void)setFont:(UIFont *)font -{ - [super setFont:font]; - - [self.suggestionLabel setFont:font]; + self.suggestionLabel.font = font; } #pragma mark - UIResponder - -- (BOOL)becomeFirstResponder -{ - if (!self.suggestionsDisabled) - { - if ([self clearsOnBeginEditing]) - { - self.suggestionLabel.text = @""; - } - - self.suggestionLabel.hidden = NO; +- (BOOL)becomeFirstResponder { + if (!self.suggestionsDisabled) { + if ([self clearsOnBeginEditing]) { + self.suggestionLabel.text = @""; } - - return [super becomeFirstResponder]; + + self.suggestionLabel.hidden = NO; + } + + return [super becomeFirstResponder]; } -- (BOOL)resignFirstResponder -{ - if (!self.suggestionsDisabled) - { - self.suggestionLabel.hidden = YES; +- (BOOL)resignFirstResponder { + if (!self.suggestionsDisabled) { + self.suggestionLabel.hidden = YES; - [self acceptSuggestionText]; - } - return [super resignFirstResponder]; + [self acceptSuggestionText]; + } + + return [super resignFirstResponder]; } #pragma mark - Autocomplete Logic - -- (CGRect)suggestionLabelRectForBounds:(CGRect)bounds -{ - CGRect returnRect = CGRectZero; - CGRect textContainerBounds = [self textRectForBounds:self.bounds]; - - UITextRange *textRange = [self textRangeFromPosition:[self beginningOfDocument] toPosition:[self endOfDocument]]; - CGRect textRect = CGRectIntegral([self firstRectForRange:textRange]); - - NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; - paragraphStyle.lineBreakMode = self.suggestionLabel.lineBreakMode; - - CGRect prefixTextRect = [self.text boundingRectWithSize:textContainerBounds.size - options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading - attributes:@{ - NSFontAttributeName: self.font, - NSParagraphStyleAttributeName: paragraphStyle, - } - context:nil]; - CGSize prefixTextSize = prefixTextRect.size; - - CGRect suggestionTextRect = [self.suggestionString boundingRectWithSize:CGSizeMake(textContainerBounds.size.width - prefixTextSize.width, textContainerBounds.size.height) - options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading - attributes:@{ - NSFontAttributeName : self.suggestionLabel.font, - NSParagraphStyleAttributeName : paragraphStyle, - } - context:nil]; - CGSize suggestionTextSize = suggestionTextRect.size; - - returnRect = CGRectMake(CGRectGetMinX(textContainerBounds) + CGRectGetMaxX(textRect) + self.suggestionLabelExtraPositionOffset.x, - CGRectGetMinY(textContainerBounds) + self.suggestionLabelExtraPositionOffset.y, - suggestionTextSize.width, - textContainerBounds.size.height); - - return returnRect; +- (CGRect)suggestionLabelRectForBounds:(CGRect __unused)bounds { + CGRect returnRect = CGRectZero; + CGRect textContainerBounds = [self textRectForBounds:self.bounds]; + UITextRange *textRange = [self textRangeFromPosition:self.beginningOfDocument + toPosition:self.endOfDocument]; + CGRect textRect = CGRectIntegral([self firstRectForRange:textRange]); + NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; + paragraphStyle.lineBreakMode = self.suggestionLabel.lineBreakMode; + + CGRect prefixTextRect = [self.text boundingRectWithSize:textContainerBounds.size + options:(NSStringDrawingOptions)(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) + attributes:@{NSFontAttributeName:self.font, + NSParagraphStyleAttributeName:paragraphStyle} + context:nil]; + CGSize prefixTextSize = prefixTextRect.size; + + CGRect suggestionTextRect = [self.suggestionString boundingRectWithSize:CGSizeMake(textContainerBounds.size.width - prefixTextSize.width, textContainerBounds.size.height) + options:(NSStringDrawingOptions)(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) + attributes:@{NSFontAttributeName:self.suggestionLabel.font, + NSParagraphStyleAttributeName:paragraphStyle} + context:nil]; + CGSize suggestionTextSize = suggestionTextRect.size; + + returnRect = CGRectMake(CGRectGetMinX(textContainerBounds) + CGRectGetMaxX(textRect) + self.suggestionLabelExtraPositionOffset.x, + CGRectGetMinY(textContainerBounds) + self.suggestionLabelExtraPositionOffset.y, + suggestionTextSize.width, + textContainerBounds.size.height); + + return returnRect; } -- (void)ht_textDidChangeNotificationFired:(NSNotification*)notification -{ - [self refreshSuggestionText]; +- (void)ht_textDidChangeNotificationFired:(NSNotification * __unused)notification { + [self refreshSuggestionText]; } -- (void)updateSuggestionLabel -{ - [self.suggestionLabel setText:self.suggestionString]; - [self.suggestionLabel sizeToFit]; - [self.suggestionLabel setFrame:[self suggestionLabelRectForBounds:self.bounds]]; - - if ([self.autocompleteTextFieldDelegate respondsToSelector:@selector(autocompleteTextField:didChangeSuggestionText:)]) - { - [self.autocompleteTextFieldDelegate autocompleteTextField:self didChangeSuggestionText:self.suggestionString]; - } +- (void)updateSuggestionLabel { + self.suggestionLabel.text = self.suggestionString; + [self.suggestionLabel sizeToFit]; + self.suggestionLabel.frame = [self suggestionLabelRectForBounds:self.bounds]; + + if ([self.autocompleteTextFieldDelegate respondsToSelector:@selector(autocompleteTextField:didChangeSuggestionText:)]) { + [self.autocompleteTextFieldDelegate autocompleteTextField:self didChangeSuggestionText:self.suggestionString]; + } } -- (void)refreshSuggestionText -{ - if (!self.suggestionsDisabled) - { - id dataSource = nil; - - if ([self.suggestionDataSource respondsToSelector:@selector(textField:completionForPrefix:)]) - { - dataSource = (id )self.suggestionDataSource; - } - - if (dataSource) - { - self.suggestionString = [dataSource textField:self completionForPrefix:self.text]; - - [self updateSuggestionLabel]; - } - else - { +- (void)refreshSuggestionText { + if (self.suggestionsDisabled) { + return; + } + + + id dataSource; + + if ([self.suggestionDataSource respondsToSelector:@selector(textField:completionForPrefix:)]) { + // Bind the weak var to a string var + dataSource = (id )self.suggestionDataSource; + } + + if (dataSource) { + self.suggestionString = [dataSource textField:self + completionForPrefix:self.text]; + + [self updateSuggestionLabel]; + } + else { #if DEBUG - NSLog(@"Note: a data source is required for HTAutocompleteTextField to suggest text"); + NSLog(@"Note: a data source is required for HTAutocompleteTextField to suggest text"); #endif - } - } + } + } -- (void)acceptSuggestionText -{ - if (![self.suggestionString isEqualToString:@""] && !self.suggestionsDisabled) - { - self.text = [NSString stringWithFormat:@"%@%@", self.text, self.suggestionString]; - - self.suggestionString = @""; - [self updateSuggestionLabel]; - - if ([self.autocompleteTextFieldDelegate respondsToSelector:@selector(autocompleteTextFieldSuggestionTextWasAccepted:)]) { - [self.autocompleteTextFieldDelegate autocompleteTextFieldSuggestionTextWasAccepted:self]; - } - - // We must fire these events manually because programmatic changes to self.text do not do so automatically - [self sendActionsForControlEvents:UIControlEventEditingChanged]; - [[NSNotificationCenter defaultCenter] postNotificationName:UITextFieldTextDidChangeNotification object:self]; - } +- (void)acceptSuggestionText { + if ([self.suggestionString isEqualToString:@""] || self.suggestionsDisabled) { + return; + } + + self.text = [NSString stringWithFormat:@"%@%@", self.text, self.suggestionString]; + + self.suggestionString = @""; + [self updateSuggestionLabel]; + + if ([self.autocompleteTextFieldDelegate respondsToSelector:@selector(autocompleteTextFieldSuggestionTextWasAccepted:)]) { + [self.autocompleteTextFieldDelegate autocompleteTextFieldSuggestionTextWasAccepted:self]; + } + + // We must fire these events manually because programmatic changes to + // self.text do not do so automatically + [self sendActionsForControlEvents:UIControlEventEditingChanged]; + [[NSNotificationCenter defaultCenter] postNotificationName:UITextFieldTextDidChangeNotification + object:self]; } @end diff --git a/Classes/HTEmailAutocompleteTextField.m b/Classes/HTEmailAutocompleteTextField.m index a4272ed..ffedf4d 100644 --- a/Classes/HTEmailAutocompleteTextField.m +++ b/Classes/HTEmailAutocompleteTextField.m @@ -10,69 +10,59 @@ @implementation HTEmailAutocompleteTextField -- (void)setupAutocompleteTextField -{ - [super setupAutocompleteTextField]; - - // Default email domains to suggest - self.emailDomains = @[ @"gmail.com", @"yahoo.com", @"hotmail.com", @"aol.com", @"comcast.net", @"me.com", @"msn.com", @"live.com", @"sbcglobal.net", @"ymail.com", @"att.net", @"mac.com", @"cox.net", @"verizon.net", @"hotmail.co.uk", @"bellsouth.net", @"rocketmail.com", @"aim.com", @"yahoo.co.uk", @"earthlink.net", @"charter.net", @"optonline.net", @"shaw.ca", @"yahoo.ca", @"googlemail.com", @"mail.com", @"qq.com", @"btinternet.com", @"mail.ru", @"live.co.uk", @"naver.com", @"rogers.com", @"juno.com", @"yahoo.com.tw", @"live.ca", @"walla.com", @"163.com", @"roadrunner.com", @"telus.net", @"embarqmail.com", @"hotmail.fr", @"pacbell.net", @"sky.com", @"sympatico.ca", @"cfl.rr.com", @"tampabay.rr.com", @"q.com", @"yahoo.co.in", @"yahoo.fr", @"hotmail.ca", @"windstream.net", @"hotmail.it", @"web.de", @"asu.edu", @"gmx.de", @"gmx.com", @"insightbb.com", @"netscape.net", @"icloud.com", @"frontier.com", @"126.com", @"hanmail.net", @"suddenlink.net", @"netzero.net", @"mindspring.com", @"ail.com", @"windowslive.com", @"netzero.com", @"yahoo.com.hk", @"yandex.ru", @"mchsi.com", @"cableone.net", @"yahoo.com.cn", @"yahoo.es", @"yahoo.com.br", @"cornell.edu", @"ucla.edu", @"us.army.mil", @"excite.com", @"ntlworld.com", @"usc.edu", @"nate.com", @"outlook.com", @"nc.rr.com", @"prodigy.net", @"wi.rr.com", @"videotron.ca", @"yahoo.it", @"yahoo.com.au", @"umich.edu", @"ameritech.net", @"libero.it", @"yahoo.de", @"rochester.rr.com", @"cs.com", @"frontiernet.net", @"swbell.net", @"msu.edu", @"ptd.net", @"proxymail.facebook.com", @"hotmail.es", @"austin.rr.com", @"nyu.edu", @"sina.com", @"centurytel.net", @"usa.net", @"nycap.rr.com", @"uci.edu", @"hotmail.de", @"yahoo.com.sg", @"email.arizona.edu", @"yahoo.com.mx", @"ufl.edu", @"bigpond.com", @"unlv.nevada.edu", @"yahoo.cn", @"ca.rr.com", @"google.com", @"yahoo.co.id", @"inbox.com", @"fuse.net", @"hawaii.rr.com", @"talktalk.net", @"gmx.net", @"walla.co.il", @"ucdavis.edu", @"carolina.rr.com", @"comcast.com", @"live.fr", @"blueyonder.co.uk", @"live.cn", @"cogeco.ca", @"abv.bg", @"tds.net", @"centurylink.net", @"yahoo.com.vn", @"uol.com.br", @"osu.edu", @"san.rr.com", @"rcn.com", @"umn.edu", @"live.nl", @"live.com.au", @"tx.rr.com", @"eircom.net", @"sasktel.net", @"post.harvard.edu", @"snet.net", @"wowway.com", @"live.it", @"hoteltonight.com", @"att.com", @"vt.edu", @"rambler.ru", @"temple.edu", @"cinci.rr.com"]; - - self.suggestionDataSource = self; +- (void)setupAutocompleteTextField { + [super setupAutocompleteTextField]; + + // Default email domains to suggest + self.emailDomains = @[@"gmail.com", @"yahoo.com", @"hotmail.com", @"aol.com", @"comcast.net", @"me.com", @"msn.com", @"live.com", @"sbcglobal.net", @"ymail.com", @"att.net", @"mac.com", @"cox.net", @"verizon.net", @"hotmail.co.uk", @"bellsouth.net", @"rocketmail.com", @"aim.com", @"yahoo.co.uk", @"earthlink.net", @"charter.net", @"optonline.net", @"shaw.ca", @"yahoo.ca", @"googlemail.com", @"mail.com", @"qq.com", @"btinternet.com", @"mail.ru", @"live.co.uk", @"naver.com", @"rogers.com", @"juno.com", @"yahoo.com.tw", @"live.ca", @"walla.com", @"163.com", @"roadrunner.com", @"telus.net", @"embarqmail.com", @"hotmail.fr", @"pacbell.net", @"sky.com", @"sympatico.ca", @"cfl.rr.com", @"tampabay.rr.com", @"q.com", @"yahoo.co.in", @"yahoo.fr", @"hotmail.ca", @"windstream.net", @"hotmail.it", @"web.de", @"asu.edu", @"gmx.de", @"gmx.com", @"insightbb.com", @"netscape.net", @"icloud.com", @"frontier.com", @"126.com", @"hanmail.net", @"suddenlink.net", @"netzero.net", @"mindspring.com", @"ail.com", @"windowslive.com", @"netzero.com", @"yahoo.com.hk", @"yandex.ru", @"mchsi.com", @"cableone.net", @"yahoo.com.cn", @"yahoo.es", @"yahoo.com.br", @"cornell.edu", @"ucla.edu", @"us.army.mil", @"excite.com", @"ntlworld.com", @"usc.edu", @"nate.com", @"outlook.com", @"nc.rr.com", @"prodigy.net", @"wi.rr.com", @"videotron.ca", @"yahoo.it", @"yahoo.com.au", @"umich.edu", @"ameritech.net", @"libero.it", @"yahoo.de", @"rochester.rr.com", @"cs.com", @"frontiernet.net", @"swbell.net", @"msu.edu", @"ptd.net", @"proxymail.facebook.com", @"hotmail.es", @"austin.rr.com", @"nyu.edu", @"sina.com", @"centurytel.net", @"usa.net", @"nycap.rr.com", @"uci.edu", @"hotmail.de", @"yahoo.com.sg", @"email.arizona.edu", @"yahoo.com.mx", @"ufl.edu", @"bigpond.com", @"unlv.nevada.edu", @"yahoo.cn", @"ca.rr.com", @"google.com", @"yahoo.co.id", @"inbox.com", @"fuse.net", @"hawaii.rr.com", @"talktalk.net", @"gmx.net", @"walla.co.il", @"ucdavis.edu", @"carolina.rr.com", @"comcast.com", @"live.fr", @"blueyonder.co.uk", @"live.cn", @"cogeco.ca", @"abv.bg", @"tds.net", @"centurylink.net", @"yahoo.com.vn", @"uol.com.br", @"osu.edu", @"san.rr.com", @"rcn.com", @"umn.edu", @"live.nl", @"live.com.au", @"tx.rr.com", @"eircom.net", @"sasktel.net", @"post.harvard.edu", @"snet.net", @"wowway.com", @"live.it", @"hoteltonight.com", @"att.com", @"vt.edu", @"rambler.ru", @"temple.edu", @"cinci.rr.com"]; + + self.suggestionDataSource = self; } #pragma mark - HTAutocompleteSuggestionDataSource -- (NSString *)textField:(HTAutocompleteTextField *)textField completionForPrefix:(NSString *)prefix -{ - // Check that text field contains an @ - NSRange atSignRange = [prefix rangeOfString:@"@"]; - if (atSignRange.location == NSNotFound) - { - return @""; - } - - // Stop autocomplete if user types dot after domain - NSString *domainAndTLD = [prefix substringFromIndex:atSignRange.location]; - NSRange rangeOfDot = [domainAndTLD rangeOfString:@"."]; - if (rangeOfDot.location != NSNotFound) - { - return @""; - } +- (NSString *)textField:(HTAutocompleteTextField * __unused)textField completionForPrefix:(NSString *)prefix { + // Check that text field contains an @ + NSRange atSignRange = [prefix rangeOfString:@"@"]; + if (atSignRange.location == NSNotFound) { + return @""; + } - // Check that there aren't two @-signs - NSArray *textComponents = [prefix componentsSeparatedByString:@"@"]; - if ([textComponents count] > 2) - { - return @""; - } + // Stop autocomplete if user types dot after domain + NSString *domainAndTLD = [prefix substringFromIndex:atSignRange.location]; + NSRange rangeOfDot = [domainAndTLD rangeOfString:@"."]; + if (rangeOfDot.location != NSNotFound) { + return @""; + } - if ([textComponents count] > 1) - { - // If no domain is entered, use the first domain in the list - if ([(NSString *)textComponents[1] length] == 0) - { - return self.emailDomains[0]; - } + // Check that there aren't two @-signs + NSArray *textComponents = [prefix componentsSeparatedByString:@"@"]; + if ([textComponents count] > 2) { + return @""; + } - NSString *textAfterAtSign = textComponents[1]; + if ([textComponents count] > 1) { + // If no domain is entered, use the first domain in the list + if ([(NSString *)textComponents[1] length] == 0) { + return self.emailDomains[0]; + } - NSString *stringToLookFor; - stringToLookFor = [textAfterAtSign lowercaseString]; + NSString *textAfterAtSign = textComponents[1]; - for (NSString *stringFromReference in self.emailDomains) - { - NSString *stringToCompare; - stringToCompare = [stringFromReference lowercaseString]; + NSString *stringToLookFor; + stringToLookFor = [textAfterAtSign lowercaseString]; - if ([stringToCompare hasPrefix:stringToLookFor]) - { - return [stringFromReference stringByReplacingCharactersInRange:[stringToCompare rangeOfString:stringToLookFor] withString:@""]; - } + for (NSString *stringFromReference in self.emailDomains) { + NSString *stringToCompare; + stringToCompare = [stringFromReference lowercaseString]; - } + if ([stringToCompare hasPrefix:stringToLookFor]) { + return [stringFromReference stringByReplacingCharactersInRange:[stringToCompare rangeOfString:stringToLookFor] withString:@""]; + } } - - return @""; + } + + return @""; } diff --git a/HTTextFieldAutocompletionExample.xcodeproj/project.pbxproj b/HTTextFieldAutocompletionExample.xcodeproj/project.pbxproj index 3ba3255..8852d18 100644 --- a/HTTextFieldAutocompletionExample.xcodeproj/project.pbxproj +++ b/HTTextFieldAutocompletionExample.xcodeproj/project.pbxproj @@ -10,9 +10,6 @@ 8D86FEEE16E96D4800534BDD /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D86FEED16E96D4800534BDD /* MainStoryboard.storyboard */; }; 8D9AF2FA19F19FA8003210C8 /* HTAutocompleteTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D9AF2F719F19FA8003210C8 /* HTAutocompleteTextField.m */; }; 8D9AF2FB19F19FA8003210C8 /* HTEmailAutocompleteTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D9AF2F919F19FA8003210C8 /* HTEmailAutocompleteTextField.m */; }; - 8DF4A805168B7C610025E16D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DF4A804168B7C610025E16D /* UIKit.framework */; }; - 8DF4A807168B7C610025E16D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DF4A806168B7C610025E16D /* Foundation.framework */; }; - 8DF4A809168B7C610025E16D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DF4A808168B7C610025E16D /* CoreGraphics.framework */; }; 8DF4A80F168B7C610025E16D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8DF4A80D168B7C610025E16D /* InfoPlist.strings */; }; 8DF4A811168B7C610025E16D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DF4A810168B7C610025E16D /* main.m */; }; 8DF4A815168B7C610025E16D /* HTAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DF4A814168B7C610025E16D /* HTAppDelegate.m */; }; @@ -27,16 +24,12 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 541886FBCF924E768C27BA1C /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 8D86FEED16E96D4800534BDD /* MainStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = MainStoryboard.storyboard; sourceTree = ""; }; 8D9AF2F619F19FA8003210C8 /* HTAutocompleteTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTAutocompleteTextField.h; sourceTree = ""; }; 8D9AF2F719F19FA8003210C8 /* HTAutocompleteTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTAutocompleteTextField.m; sourceTree = ""; }; 8D9AF2F819F19FA8003210C8 /* HTEmailAutocompleteTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTEmailAutocompleteTextField.h; sourceTree = ""; }; 8D9AF2F919F19FA8003210C8 /* HTEmailAutocompleteTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTEmailAutocompleteTextField.m; sourceTree = ""; }; 8DF4A800168B7C610025E16D /* HTTextFieldAutocompletionExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HTTextFieldAutocompletionExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 8DF4A804168B7C610025E16D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - 8DF4A806168B7C610025E16D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - 8DF4A808168B7C610025E16D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 8DF4A80C168B7C610025E16D /* HTTextFieldAutocompletionExample-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "HTTextFieldAutocompletionExample-Info.plist"; sourceTree = ""; }; 8DF4A80E168B7C610025E16D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 8DF4A810168B7C610025E16D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -60,9 +53,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8DF4A805168B7C610025E16D /* UIKit.framework in Frameworks */, - 8DF4A807168B7C610025E16D /* Foundation.framework in Frameworks */, - 8DF4A809168B7C610025E16D /* CoreGraphics.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -85,7 +75,6 @@ children = ( 8D9AF2F519F19FA8003210C8 /* Classes */, 8DF4A80A168B7C610025E16D /* HTTextFieldAutocompletionExample */, - 8DF4A803168B7C610025E16D /* Frameworks */, 8DF4A801168B7C610025E16D /* Products */, ); sourceTree = ""; @@ -98,17 +87,6 @@ name = Products; sourceTree = ""; }; - 8DF4A803168B7C610025E16D /* Frameworks */ = { - isa = PBXGroup; - children = ( - 8DF4A804168B7C610025E16D /* UIKit.framework */, - 8DF4A806168B7C610025E16D /* Foundation.framework */, - 8DF4A808168B7C610025E16D /* CoreGraphics.framework */, - 541886FBCF924E768C27BA1C /* libPods.a */, - ); - name = Frameworks; - sourceTree = ""; - }; 8DF4A80A168B7C610025E16D /* HTTextFieldAutocompletionExample */ = { isa = PBXGroup; children = ( @@ -246,13 +224,28 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; + CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; + CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_ASSIGN_ENUM = YES; + CLANG_WARN_CXX0X_EXTENSIONS = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; + CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES; + CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES; COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_C_LANGUAGE_STANDARD = "compiler-default"; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -260,13 +253,33 @@ "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; + GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES; + GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; + GCC_WARN_PEDANTIC = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_STRICT_SELECTOR_MATCH = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNKNOWN_PRAGMAS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.1; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = 1; }; name = Debug; }; @@ -274,20 +287,55 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; + CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; + CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_ASSIGN_ENUM = YES; + CLANG_WARN_CXX0X_EXTENSIONS = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; + CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES; + CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES; COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_C_LANGUAGE_STANDARD = "compiler-default"; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; + GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES; + GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; + GCC_WARN_PEDANTIC = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_STRICT_SELECTOR_MATCH = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNKNOWN_PRAGMAS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.1; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = 1; VALIDATE_PRODUCT = YES; }; name = Release; @@ -295,10 +343,11 @@ 8DF4A828168B7C610025E16D /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "HTTextFieldAutocompletionExample/HTTextFieldAutocompletionExample-Prefix.pch"; INFOPLIST_FILE = "HTTextFieldAutocompletionExample/HTTextFieldAutocompletionExample-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.1; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = 1; WRAPPER_EXTENSION = app; @@ -308,10 +357,11 @@ 8DF4A829168B7C610025E16D /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "HTTextFieldAutocompletionExample/HTTextFieldAutocompletionExample-Prefix.pch"; INFOPLIST_FILE = "HTTextFieldAutocompletionExample/HTTextFieldAutocompletionExample-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 5.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.1; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = 1; WRAPPER_EXTENSION = app; diff --git a/HTTextFieldAutocompletionExample/HTAppDelegate.h b/HTTextFieldAutocompletionExample/HTAppDelegate.h index fcc78f4..8f1e62a 100644 --- a/HTTextFieldAutocompletionExample/HTAppDelegate.h +++ b/HTTextFieldAutocompletionExample/HTAppDelegate.h @@ -6,14 +6,12 @@ // Copyright (c) 2012 Hotel Tonight. All rights reserved. // -#import +@import UIKit; @class HTViewController; @interface HTAppDelegate : UIResponder -@property (strong, nonatomic) UIWindow *window; - -@property (strong, nonatomic) HTViewController *viewController; +@property (nonatomic) UIWindow *window; @end diff --git a/HTTextFieldAutocompletionExample/HTAppDelegate.m b/HTTextFieldAutocompletionExample/HTAppDelegate.m index 4f7a7f8..5314298 100644 --- a/HTTextFieldAutocompletionExample/HTAppDelegate.m +++ b/HTTextFieldAutocompletionExample/HTAppDelegate.m @@ -10,36 +10,4 @@ @implementation HTAppDelegate -//- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -//{ -// return YES; -//} - -- (void)applicationWillResignActive:(UIApplication *)application -{ - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application -{ - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application -{ - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application -{ - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application -{ - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. -} - @end diff --git a/HTTextFieldAutocompletionExample/HTSampleAutocompleteDataSource.h b/HTTextFieldAutocompletionExample/HTSampleAutocompleteDataSource.h index b6cb812..4b62ea0 100644 --- a/HTTextFieldAutocompletionExample/HTSampleAutocompleteDataSource.h +++ b/HTTextFieldAutocompletionExample/HTSampleAutocompleteDataSource.h @@ -6,12 +6,12 @@ // Copyright (c) 2012 Hotel Tonight. All rights reserved. // -#import +@import Foundation; #import "HTAutocompleteTextField.h" typedef enum { - HTAutocompleteTypeEmail, // Default - HTAutocompleteTypeColor, + HTAutocompleteTypeEmail, // Default + HTAutocompleteTypeColor, } HTAutocompleteType; @interface HTSampleAutocompleteDataSource : NSObject diff --git a/HTTextFieldAutocompletionExample/HTSampleAutocompleteDataSource.m b/HTTextFieldAutocompletionExample/HTSampleAutocompleteDataSource.m index a8c7a3f..07e9995 100644 --- a/HTTextFieldAutocompletionExample/HTSampleAutocompleteDataSource.m +++ b/HTTextFieldAutocompletionExample/HTSampleAutocompleteDataSource.m @@ -14,74 +14,65 @@ @implementation HTSampleAutocompleteDataSource #pragma mark - HTAutocompleteTextFieldDelegate -- (NSString *)textField:(HTAutocompleteTextField *)textField - completionForPrefix:(NSString *)prefix -{ - static BOOL const IgnoreCase = YES; - - static dispatch_once_t colorOnceToken; - static NSArray *colorAutocompleteArray; - dispatch_once(&colorOnceToken, ^ { - colorAutocompleteArray = @[ @"Alfred", - @"Beth", - @"Carlos", - @"Daniel", - @"Ethan", - @"Fred", - @"George", - @"Helen", - @"Inis", - @"Jennifer", - @"Kylie", - @"Liam", - @"Melissa", - @"Noah", - @"Omar", - @"Penelope", - @"Quan", - @"Rachel", - @"Seth", - @"Timothy", - @"Ulga", - @"Vanessa", - @"William", - @"Xao", - @"Yilton", - @"Zander"]; - }); - - NSString *stringToLookFor; - NSArray *componentsString = [prefix componentsSeparatedByString:@","]; - NSString *prefixLastComponent = [componentsString.lastObject stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - if (IgnoreCase) - { - stringToLookFor = [prefixLastComponent lowercaseString]; +- (NSString *)textField:(HTAutocompleteTextField * __unused)textField completionForPrefix:(NSString *)prefix { + static BOOL const IgnoreCase = YES; + + static dispatch_once_t colorOnceToken; + static NSArray *colorAutocompleteArray; + dispatch_once(&colorOnceToken, ^ { + colorAutocompleteArray = @[ @"Alfred", + @"Beth", + @"Carlos", + @"Daniel", + @"Ethan", + @"Fred", + @"George", + @"Helen", + @"Inis", + @"Jennifer", + @"Kylie", + @"Liam", + @"Melissa", + @"Noah", + @"Omar", + @"Penelope", + @"Quan", + @"Rachel", + @"Seth", + @"Timothy", + @"Ulga", + @"Vanessa", + @"William", + @"Xao", + @"Yilton", + @"Zander"]; + }); + + NSString *stringToLookFor; + NSArray *componentsString = [prefix componentsSeparatedByString:@","]; + NSString *prefixLastComponent = [componentsString.lastObject stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if (IgnoreCase) { + stringToLookFor = [prefixLastComponent lowercaseString]; + } + else { + stringToLookFor = prefixLastComponent; + } + + for (NSString *stringFromReference in colorAutocompleteArray) { + NSString *stringToCompare; + if (IgnoreCase) { + stringToCompare = [stringFromReference lowercaseString]; } - else - { - stringToLookFor = prefixLastComponent; + else { + stringToCompare = stringFromReference; } - - for (NSString *stringFromReference in colorAutocompleteArray) - { - NSString *stringToCompare; - if (IgnoreCase) - { - stringToCompare = [stringFromReference lowercaseString]; - } - else - { - stringToCompare = stringFromReference; - } - - if ([stringToCompare hasPrefix:stringToLookFor]) - { - return [stringFromReference stringByReplacingCharactersInRange:[stringToCompare rangeOfString:stringToLookFor] withString:@""]; - } - + + if ([stringToCompare hasPrefix:stringToLookFor]) { + return [stringFromReference stringByReplacingCharactersInRange:[stringToCompare rangeOfString:stringToLookFor] withString:@""]; } - - return @""; + } + + return @""; } @end diff --git a/HTTextFieldAutocompletionExample/HTSampleFieldsTableViewController.h b/HTTextFieldAutocompletionExample/HTSampleFieldsTableViewController.h index 1c4787f..1992cc8 100644 --- a/HTTextFieldAutocompletionExample/HTSampleFieldsTableViewController.h +++ b/HTTextFieldAutocompletionExample/HTSampleFieldsTableViewController.h @@ -6,13 +6,10 @@ // Copyright (c) 2012 Hotel Tonight. All rights reserved. // -#import +@import UIKit; #import "HTAutocompleteTextField.h" #import "HTEmailAutocompleteTextField.h" @interface HTSampleFieldsTableViewController : UITableViewController -@property (unsafe_unretained, nonatomic) IBOutlet HTEmailAutocompleteTextField *emailTextField; -@property (unsafe_unretained, nonatomic) IBOutlet HTAutocompleteTextField *nameTextField; - @end diff --git a/HTTextFieldAutocompletionExample/HTSampleFieldsTableViewController.m b/HTTextFieldAutocompletionExample/HTSampleFieldsTableViewController.m index 4aa34a7..05bfbb2 100644 --- a/HTTextFieldAutocompletionExample/HTSampleFieldsTableViewController.m +++ b/HTTextFieldAutocompletionExample/HTSampleFieldsTableViewController.m @@ -11,29 +11,31 @@ @interface HTSampleFieldsTableViewController () +@property (nonatomic, weak) IBOutlet HTEmailAutocompleteTextField *emailTextField; +@property (nonatomic, weak) IBOutlet HTAutocompleteTextField *nameTextField; + @end @implementation HTSampleFieldsTableViewController -- (void)viewDidLoad -{ - [super viewDidLoad]; +- (void)viewDidLoad { + [super viewDidLoad]; + + self.emailTextField.keyboardType = UIKeyboardTypeEmailAddress; + self.emailTextField.suggestionLabelExtraPositionOffset = CGPointMake(0, -1); - self.emailTextField.keyboardType = UIKeyboardTypeEmailAddress; - self.emailTextField.suggestionLabelExtraPositionOffset = CGPointMake(0, -1); + self.nameTextField.suggestionDataSource = [HTSampleAutocompleteDataSource new]; + self.nameTextField.suggestionLabelExtraPositionOffset = CGPointMake(0, -0.5); - self.nameTextField.suggestionDataSource = [[HTSampleAutocompleteDataSource alloc] init]; - self.nameTextField.suggestionLabelExtraPositionOffset = CGPointMake(0, -0.5); - - // Dismiss the keyboard when the user taps outside of a text field - UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; - [self.view addGestureRecognizer:singleTap]; + // Dismiss the keyboard when the user taps outside of a text field + UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(handleSingleTap:)]; + [self.view addGestureRecognizer:singleTap]; } -- (void)handleSingleTap:(UITapGestureRecognizer *)sender -{ - [self.emailTextField resignFirstResponder]; - [self.nameTextField resignFirstResponder]; +- (void)handleSingleTap:(UITapGestureRecognizer * __unused)sender { + [self.emailTextField resignFirstResponder]; + [self.nameTextField resignFirstResponder]; } @end diff --git a/HTTextFieldAutocompletionExample/HTTextFieldAutocompletionExample-Info.plist b/HTTextFieldAutocompletionExample/HTTextFieldAutocompletionExample-Info.plist index 1f667cf..681fef8 100644 --- a/HTTextFieldAutocompletionExample/HTTextFieldAutocompletionExample-Info.plist +++ b/HTTextFieldAutocompletionExample/HTTextFieldAutocompletionExample-Info.plist @@ -9,7 +9,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.hoteltonight.${PRODUCT_NAME:rfc1034identifier} + com.hoteltonight.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/HTTextFieldAutocompletionExample/MainStoryboard.storyboard b/HTTextFieldAutocompletionExample/MainStoryboard.storyboard index c026839..eb4ca4b 100644 --- a/HTTextFieldAutocompletionExample/MainStoryboard.storyboard +++ b/HTTextFieldAutocompletionExample/MainStoryboard.storyboard @@ -1,8 +1,8 @@ - + - - + + @@ -128,7 +128,7 @@ - + @@ -156,4 +156,4 @@ - \ No newline at end of file +