Skip to content

Commit

Permalink
Get rid of unnecessary allocations of NBPhoneNumberUtil and use shared
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaclach committed Mar 20, 2017
1 parent 5fcfb55 commit 6c3c6a6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions MetadataGenerator/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

- (void)testForGetSupportedRegions
{
NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init];
NBPhoneNumberUtil *phoneUtil = [NBPhoneNumberUtil sharedInstance];
NSLog(@"%@", [phoneUtil getSupportedRegions]);
}

Expand Down Expand Up @@ -74,7 +74,7 @@ - (void)testWithRealData

// Unit test for isValidNumber is failing some valid numbers. #7

NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init];
NBPhoneNumberUtil *phoneUtil = [NBPhoneNumberUtil sharedInstance];

{
NSError *error = nil;
Expand Down Expand Up @@ -212,7 +212,7 @@ - (NSString *)randomRegion

- (void)testForMultithread
{
NBPhoneNumberUtil *aUtil = [[NBPhoneNumberUtil alloc] init];
NBPhoneNumberUtil *aUtil = [NBPhoneNumberUtil sharedInstance];
NSString *testRegion = [self randomRegion];

if (!testRegion) {
Expand Down Expand Up @@ -272,7 +272,7 @@ - (void)testCarrierRegion

- (NSString *)getPhoneNumberFormatted:(NSString *)phoneNumber
{
NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init];
NBPhoneNumberUtil *phoneUtil = [NBPhoneNumberUtil sharedInstance];
NSString *retValue;
NBPhoneNumber *phoneNumberFormatted = [phoneUtil parseWithPhoneCarrierRegion:phoneNumber error:nil];
retValue = [phoneUtil format:phoneNumberFormatted numberFormat:NBEPhoneNumberFormatRFC3966 error:nil];
Expand All @@ -283,7 +283,7 @@ - (NSString *)getPhoneNumberFormatted:(NSString *)phoneNumber
// FIXME: This unit test ALWAYS FAIL ... until google libPhoneNumber fix this issue
- (void)testAustriaNationalNumberParsing
{
NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init];
NBPhoneNumberUtil *phoneUtil = [NBPhoneNumberUtil sharedInstance];

NSError *anError = nil;

Expand All @@ -302,7 +302,7 @@ - (void)testAustriaNationalNumberParsing

- (void)testForiOS7
{
NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init];
NBPhoneNumberUtil *phoneUtil = [NBPhoneNumberUtil sharedInstance];

NSError *anError = nil;
NBPhoneNumber *myNumber = [phoneUtil parse:@"0174 2340XXX" defaultRegion:@"DE" error:&anError];
Expand Down
4 changes: 2 additions & 2 deletions libPhoneNumber/NBAsYouTypeFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ - (id)initWithRegionCode:(NSString*)regionCode bundle:(NSBundle *)bundle
* @private
* @type {i18n.phonenumbers.PhoneNumberUtil}
*/
self.phoneUtil_ = [[NBPhoneNumberUtil alloc] init];
self.phoneUtil_ = [NBPhoneNumberUtil sharedInstance];
self.defaultCountry_ = regionCode;
self.currentMetaData_ = [self getMetadataForRegion_:self.defaultCountry_];
/**
Expand All @@ -304,7 +304,7 @@ - (id)initWithRegionCodeForTest:(NSString*)regionCode bundle:(NSBundle *)bundle
self = [self init];

if (self) {
self.phoneUtil_ = [[NBPhoneNumberUtil alloc] init];
self.phoneUtil_ = [NBPhoneNumberUtil sharedInstance];

self.defaultCountry_ = regionCode;
self.currentMetaData_ = [self getMetadataForRegion_:self.defaultCountry_];
Expand Down
1 change: 0 additions & 1 deletion libPhoneNumber/NBPhoneNumberUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,5 @@
- (BOOL)formattingRuleHasFirstGroupOnly:(NSString*)nationalPrefixFormattingRule;

@property (nonatomic, strong, readonly) NSDictionary *DIGIT_MAPPINGS;
@property (nonatomic, strong, readonly) NSBundle *libPhoneBundle;

@end
2 changes: 1 addition & 1 deletion libPhoneNumberTests/NBPhoneNumberUtilTest1.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ @implementation NBPhoneNumberUtilTest1
- (void)setUp
{
[super setUp];
_aUtil = [[NBPhoneNumberUtil alloc] init];
_aUtil = [NBPhoneNumberUtil sharedInstance];
}

- (void)tearDown
Expand Down
2 changes: 1 addition & 1 deletion libPhoneNumberTests/NBPhoneNumberUtilTest2.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ @implementation NBPhoneNumberUtilTest2
- (void)setUp
{
[super setUp];
_aUtil = [[NBPhoneNumberUtil alloc] init];
_aUtil = [NBPhoneNumberUtil sharedInstance];
}

- (void)tearDown
Expand Down

0 comments on commit 6c3c6a6

Please sign in to comment.