Refactoring

This commit is contained in:
Ali 2021-09-21 00:23:29 +03:00
parent b778c66226
commit e658555ef4
16 changed files with 96 additions and 78 deletions

View File

@ -698,6 +698,7 @@ ios_framework(
":VersionInfoPlist", ":VersionInfoPlist",
], ],
minimum_os_version = "9.0", minimum_os_version = "9.0",
extension_safe = True,
ipa_post_processor = strip_framework, ipa_post_processor = strip_framework,
deps = [ deps = [
"//submodules/MtProtoKit:MtProtoKit", "//submodules/MtProtoKit:MtProtoKit",
@ -737,6 +738,7 @@ ios_framework(
":VersionInfoPlist", ":VersionInfoPlist",
], ],
minimum_os_version = "9.0", minimum_os_version = "9.0",
extension_safe = True,
ipa_post_processor = strip_framework, ipa_post_processor = strip_framework,
deps = [ deps = [
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
@ -779,6 +781,7 @@ ios_framework(
":SwiftSignalKitFramework", ":SwiftSignalKitFramework",
], ],
minimum_os_version = "9.0", minimum_os_version = "9.0",
extension_safe = True,
ipa_post_processor = strip_framework, ipa_post_processor = strip_framework,
deps = [ deps = [
"//submodules/Postbox:Postbox", "//submodules/Postbox:Postbox",
@ -818,6 +821,7 @@ ios_framework(
":VersionInfoPlist", ":VersionInfoPlist",
], ],
minimum_os_version = "9.0", minimum_os_version = "9.0",
extension_safe = True,
ipa_post_processor = strip_framework, ipa_post_processor = strip_framework,
deps = [ deps = [
"//submodules/TelegramApi:TelegramApi", "//submodules/TelegramApi:TelegramApi",
@ -862,6 +866,7 @@ ios_framework(
":PostboxFramework", ":PostboxFramework",
], ],
minimum_os_version = "9.0", minimum_os_version = "9.0",
extension_safe = True,
ipa_post_processor = strip_framework, ipa_post_processor = strip_framework,
deps = [ deps = [
"//submodules/TelegramCore:TelegramCore", "//submodules/TelegramCore:TelegramCore",
@ -901,6 +906,7 @@ ios_framework(
":VersionInfoPlist", ":VersionInfoPlist",
], ],
minimum_os_version = "9.0", minimum_os_version = "9.0",
extension_safe = True,
ipa_post_processor = strip_framework, ipa_post_processor = strip_framework,
deps = [ deps = [
"//submodules/AsyncDisplayKit:AsyncDisplayKit", "//submodules/AsyncDisplayKit:AsyncDisplayKit",
@ -987,6 +993,7 @@ ios_framework(
":AsyncDisplayKitFramework", ":AsyncDisplayKitFramework",
], ],
minimum_os_version = "9.0", minimum_os_version = "9.0",
extension_safe = True,
ipa_post_processor = strip_framework, ipa_post_processor = strip_framework,
deps = [ deps = [
"//submodules/Display:Display", "//submodules/Display:Display",
@ -1034,6 +1041,7 @@ ios_framework(
":DisplayFramework", ":DisplayFramework",
], ],
minimum_os_version = "9.0", minimum_os_version = "9.0",
extension_safe = True,
ipa_post_processor = strip_framework, ipa_post_processor = strip_framework,
deps = [ deps = [
"//submodules/TelegramUI:TelegramUI", "//submodules/TelegramUI:TelegramUI",
@ -1096,6 +1104,9 @@ swift_library(
srcs = glob([ srcs = glob([
"Share/**/*.swift", "Share/**/*.swift",
]), ]),
copts = [
"-warnings-as-errors",
],
deps = [ deps = [
"//submodules/TelegramUI:TelegramUI" "//submodules/TelegramUI:TelegramUI"
], ],
@ -1178,6 +1189,9 @@ swift_library(
srcs = glob([ srcs = glob([
"NotificationContent/**/*.swift", "NotificationContent/**/*.swift",
]), ]),
copts = [
"-warnings-as-errors",
],
deps = [ deps = [
"//submodules/TelegramUI:TelegramUI", "//submodules/TelegramUI:TelegramUI",
":NotificationContentExtensionLink", ":NotificationContentExtensionLink",
@ -1269,6 +1283,9 @@ swift_library(
srcs = glob([ srcs = glob([
"WidgetKitWidget/**/*.swift", "WidgetKitWidget/**/*.swift",
]), ]),
copts = [
"-warnings-as-errors",
],
data = [ data = [
":WidgetAssets", ":WidgetAssets",
], ],
@ -1397,6 +1414,9 @@ swift_library(
srcs = glob([ srcs = glob([
"SiriIntents/**/*.swift", "SiriIntents/**/*.swift",
]), ]),
copts = [
"-warnings-as-errors",
],
data = glob([ data = glob([
"SiriIntents/*.lproj/Intents.intentdefinition" "SiriIntents/*.lproj/Intents.intentdefinition"
]) + [ ]) + [
@ -1496,6 +1516,9 @@ swift_library(
srcs = glob([ srcs = glob([
"BroadcastUpload/**/*.swift", "BroadcastUpload/**/*.swift",
]), ]),
copts = [
"-warnings-as-errors",
],
deps = [ deps = [
"//submodules/TelegramUI:TelegramUI", "//submodules/TelegramUI:TelegramUI",
"//submodules/TelegramVoip:TelegramVoip", "//submodules/TelegramVoip:TelegramVoip",

View File

@ -37,7 +37,7 @@ private struct ApplicationSettings {
private func applicationSettings(accountManager: AccountManager<TelegramAccountManagerTypes>) -> Signal<ApplicationSettings, NoError> { private func applicationSettings(accountManager: AccountManager<TelegramAccountManagerTypes>) -> Signal<ApplicationSettings, NoError> {
return accountManager.transaction { transaction -> ApplicationSettings in return accountManager.transaction { transaction -> ApplicationSettings in
let loggingSettings: LoggingSettings let loggingSettings: LoggingSettings
if let value = transaction.getSharedData(SharedDataKeys.loggingSettings) as? LoggingSettings { if let value = transaction.getSharedData(SharedDataKeys.loggingSettings)?.get(LoggingSettings.self) {
loggingSettings = value loggingSettings = value
} else { } else {
loggingSettings = LoggingSettings.defaultSettings loggingSettings = LoggingSettings.defaultSettings
@ -943,7 +943,7 @@ private final class WidgetIntentHandler {
if let data = try? Data(contentsOf: URL(fileURLWithPath: appLockStatePath(rootPath: rootPath))), let state = try? JSONDecoder().decode(LockState.self, from: data), isAppLocked(state: state) { if let data = try? Data(contentsOf: URL(fileURLWithPath: appLockStatePath(rootPath: rootPath))), let state = try? JSONDecoder().decode(LockState.self, from: data), isAppLocked(state: state) {
let presentationData = WidgetPresentationData.getForExtension() //let presentationData = WidgetPresentationData.getForExtension()
let error = NSError(domain: "Locked", code: 1, userInfo: [ let error = NSError(domain: "Locked", code: 1, userInfo: [
NSLocalizedDescriptionKey: "Open Telegram and enter passcode to edit widget." NSLocalizedDescriptionKey: "Open Telegram and enter passcode to edit widget."

View File

@ -36,7 +36,7 @@ func unreadMessages(account: Account) -> Signal<[INMessage], NoError> {
|> mapToSignal { view -> Signal<[INMessage], NoError> in |> mapToSignal { view -> Signal<[INMessage], NoError> in
var signals: [Signal<[INMessage], NoError>] = [] var signals: [Signal<[INMessage], NoError>] = []
for entry in view.0.entries { for entry in view.0.entries {
if case let .MessageEntry(index, _, readState, notificationSettings, _, _, _, _, _, _) = entry { if case let .MessageEntry(index, _, readState, isMuted, _, _, _, _, _, _) = entry {
if index.messageIndex.id.peerId.namespace != Namespaces.Peer.CloudUser { if index.messageIndex.id.peerId.namespace != Namespaces.Peer.CloudUser {
continue continue
} }
@ -47,12 +47,6 @@ func unreadMessages(account: Account) -> Signal<[INMessage], NoError> {
hasUnread = readState.count != 0 hasUnread = readState.count != 0
fixedCombinedReadStates = .peer([index.messageIndex.id.peerId: readState]) fixedCombinedReadStates = .peer([index.messageIndex.id.peerId: readState])
} }
var isMuted = false
if let notificationSettings = notificationSettings as? TelegramPeerNotificationSettings {
if case let .muted(until) = notificationSettings.muteState, until >= Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) {
isMuted = true
}
}
if !isMuted && hasUnread { if !isMuted && hasUnread {
signals.append(account.postbox.aroundMessageHistoryViewForLocation(.peer(index.messageIndex.id.peerId), anchor: .upperBound, count: 10, fixedCombinedReadStates: fixedCombinedReadStates, topTaggedMessageIdNamespaces: Set(), tagMask: nil, appendMessagesFromTheSameGroup: false, namespaces: .not(Namespaces.Message.allScheduled), orderStatistics: .combinedLocation) signals.append(account.postbox.aroundMessageHistoryViewForLocation(.peer(index.messageIndex.id.peerId), anchor: .upperBound, count: 10, fixedCombinedReadStates: fixedCombinedReadStates, topTaggedMessageIdNamespaces: Set(), tagMask: nil, appendMessagesFromTheSameGroup: false, namespaces: .not(Namespaces.Message.allScheduled), orderStatistics: .combinedLocation)

View File

@ -171,7 +171,7 @@ private func getCommonTimeline(friends: [Friend]?, in context: TimelineProviderC
var mappedMessage: WidgetDataPeer.Message? var mappedMessage: WidgetDataPeer.Message?
if let index = transaction.getTopPeerMessageIndex(peerId: peer.id) { if let index = transaction.getTopPeerMessageIndex(peerId: peer.id) {
if let message = transaction.getMessage(index.id) { if let message = transaction.getMessage(index.id) {
mappedMessage = WidgetDataPeer.Message(accountPeerId: state.peerId, message: message) mappedMessage = WidgetDataPeer.Message(accountPeerId: state.peerId, message: EngineMessage(message))
} }
} }

View File

@ -1,5 +1,17 @@
import Postbox import Postbox
public final class EngineMediaResource {
private let resource: MediaResource
public init(_ resource: MediaResource) {
self.resource = resource
}
public func _asResource() -> MediaResource {
return self.resource
}
}
public enum EngineMedia { public enum EngineMedia {
public typealias Id = MediaId public typealias Id = MediaId

View File

@ -227,7 +227,7 @@ final class WidgetDataContext {
name = peer.debugDisplayTitle name = peer.debugDisplayTitle
} }
result.append(WidgetDataPeer(id: peerId.toInt64(), name: name, lastName: lastName, letters: [], avatarPath: nil, badge: nil, message: WidgetDataPeer.Message(accountPeerId: account.peerId, message: message))) result.append(WidgetDataPeer(id: peerId.toInt64(), name: name, lastName: lastName, letters: [], avatarPath: nil, badge: nil, message: WidgetDataPeer.Message(accountPeerId: account.peerId, message: EngineMessage(message))))
} }
result.sort(by: { lhs, rhs in result.sort(by: { lhs, rhs in
return lhs.id < rhs.id return lhs.id < rhs.id

View File

@ -13,7 +13,6 @@ swift_library(
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
"//submodules/AsyncDisplayKit:AsyncDisplayKit", "//submodules/AsyncDisplayKit:AsyncDisplayKit",
"//submodules/Display:Display", "//submodules/Display:Display",
"//submodules/Postbox:Postbox",
"//submodules/TelegramCore:TelegramCore", "//submodules/TelegramCore:TelegramCore",
"//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramPresentationData:TelegramPresentationData",
"//submodules/ItemListUI:ItemListUI", "//submodules/ItemListUI:ItemListUI",

View File

@ -2,7 +2,6 @@ import Foundation
import UIKit import UIKit
import Display import Display
import SwiftSignalKit import SwiftSignalKit
import Postbox
import TelegramCore import TelegramCore
import TelegramPresentationData import TelegramPresentationData
import AccountContext import AccountContext

View File

@ -1,7 +1,6 @@
import Foundation import Foundation
import SwiftSignalKit import SwiftSignalKit
import TgVoipWebrtc import TgVoipWebrtc
import Postbox
import TelegramCore import TelegramCore
private final class ContextQueueImpl: NSObject, OngoingCallThreadLocalContextQueueWebrtc { private final class ContextQueueImpl: NSObject, OngoingCallThreadLocalContextQueueWebrtc {

View File

@ -15,7 +15,6 @@ swift_library(
"//submodules/GradientBackground:GradientBackground", "//submodules/GradientBackground:GradientBackground",
"//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramPresentationData:TelegramPresentationData",
"//submodules/TelegramCore:TelegramCore", "//submodules/TelegramCore:TelegramCore",
"//submodules/Postbox:Postbox",
"//submodules/AccountContext:AccountContext", "//submodules/AccountContext:AccountContext",
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
"//submodules/WallpaperResources:WallpaperResources", "//submodules/WallpaperResources:WallpaperResources",

View File

@ -8,7 +8,6 @@ import TelegramCore
import AccountContext import AccountContext
import SwiftSignalKit import SwiftSignalKit
import WallpaperResources import WallpaperResources
import Postbox
import FastBlur import FastBlur
private let motionAmount: CGFloat = 32.0 private let motionAmount: CGFloat = 32.0
@ -395,7 +394,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
} }
private struct PatternKey: Equatable { private struct PatternKey: Equatable {
var mediaId: MediaId var mediaId: EngineMedia.Id
var isLight: Bool var isLight: Bool
} }
private static var cachedSharedPattern: (PatternKey, UIImage)? private static var cachedSharedPattern: (PatternKey, UIImage)?
@ -626,19 +625,16 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
if let cachedValidPatternImage = WallpaperBackgroundNode.cachedValidPatternImage, cachedValidPatternImage.generated.wallpaper == wallpaper { if let cachedValidPatternImage = WallpaperBackgroundNode.cachedValidPatternImage, cachedValidPatternImage.generated.wallpaper == wallpaper {
self.validPatternImage = ValidPatternImage(wallpaper: cachedValidPatternImage.generated.wallpaper, generate: cachedValidPatternImage.generate) self.validPatternImage = ValidPatternImage(wallpaper: cachedValidPatternImage.generated.wallpaper, generate: cachedValidPatternImage.generate)
} else { } else {
func reference(for resource: MediaResource, media: Media, message: Message?) -> MediaResourceReference { func reference(for resource: EngineMediaResource, media: EngineMedia) -> MediaResourceReference {
if let message = message { return .wallpaper(wallpaper: .slug(file.slug), resource: resource._asResource())
return .media(media: .message(message: MessageReference(message), media: media), resource: resource)
}
return .wallpaper(wallpaper: .slug(file.slug), resource: resource)
} }
var convertedRepresentations: [ImageRepresentationWithReference] = [] var convertedRepresentations: [ImageRepresentationWithReference] = []
for representation in file.file.previewRepresentations { for representation in file.file.previewRepresentations {
convertedRepresentations.append(ImageRepresentationWithReference(representation: representation, reference: reference(for: representation.resource, media: file.file, message: nil))) convertedRepresentations.append(ImageRepresentationWithReference(representation: representation, reference: reference(for: EngineMediaResource(representation.resource), media: EngineMedia(file.file))))
} }
let dimensions = file.file.dimensions ?? PixelDimensions(width: 2000, height: 4000) let dimensions = file.file.dimensions ?? PixelDimensions(width: 2000, height: 4000)
convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: reference(for: file.file.resource, media: file.file, message: nil))) convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: reference(for: EngineMediaResource(file.file.resource), media: EngineMedia(file.file))))
let signal = patternWallpaperImage(account: self.context.account, accountManager: self.context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: true) let signal = patternWallpaperImage(account: self.context.account, accountManager: self.context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: true)
self.patternImageDisposable.set((signal self.patternImageDisposable.set((signal

View File

@ -11,7 +11,6 @@ swift_library(
], ],
deps = [ deps = [
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
"//submodules/Postbox:Postbox",
"//submodules/TelegramCore:TelegramCore", "//submodules/TelegramCore:TelegramCore",
"//submodules/WidgetItems:WidgetItems", "//submodules/WidgetItems:WidgetItems",
], ],

View File

@ -1,11 +1,9 @@
import Foundation import Foundation
import Postbox
import TelegramCore import TelegramCore
import WidgetItems import WidgetItems
public extension WidgetDataPeer.Message { public extension WidgetDataPeer.Message {
init(accountPeerId: PeerId, message: Message) { init(accountPeerId: EnginePeer.Id, message: EngineMessage) {
var content: WidgetDataPeer.Message.Content = .text var content: WidgetDataPeer.Message.Content = .text
for media in message.media { for media in message.media {
switch media { switch media {

View File

@ -16,11 +16,11 @@
@interface NSArray (NBAdditions) @interface NSArray (NBAdditions)
- (id)safeObjectAtIndex:(NSUInteger)index; - (id)customSafeObjectAtIndex:(NSUInteger)index;
@end @end
@implementation NSArray (NBAdditions) @implementation NSArray (NBAdditions)
- (id)safeObjectAtIndex:(NSUInteger)index { - (id)customSafeObjectAtIndex:(NSUInteger)index {
@synchronized(self) { @synchronized(self) {
if (index >= [self count]) return nil; if (index >= [self count]) return nil;
id res = [self objectAtIndex:index]; id res = [self objectAtIndex:index];
@ -376,7 +376,7 @@
for (unsigned int i = 0; i < possibleFormatsLength; ++i) for (unsigned int i = 0; i < possibleFormatsLength; ++i)
{ {
/** @type {i18n.phonenumbers.NumberFormat} */ /** @type {i18n.phonenumbers.NumberFormat} */
NBNumberFormat *numberFormat = [self.possibleFormats_ safeObjectAtIndex:i]; NBNumberFormat *numberFormat = [self.possibleFormats_ customSafeObjectAtIndex:i];
/** @type {string} */ /** @type {string} */
NSString *pattern = numberFormat.pattern; NSString *pattern = numberFormat.pattern;
@ -424,7 +424,7 @@
for (unsigned int i = 0; i < formatListLength; ++i) for (unsigned int i = 0; i < formatListLength; ++i)
{ {
/** @type {i18n.phonenumbers.NumberFormat} */ /** @type {i18n.phonenumbers.NumberFormat} */
NBNumberFormat *format = [formatList safeObjectAtIndex:i]; NBNumberFormat *format = [formatList customSafeObjectAtIndex:i];
/** @type {BOOL} */ /** @type {BOOL} */
BOOL nationalPrefixIsUsedByCountry = (self.currentMetaData_.nationalPrefix && self.currentMetaData_.nationalPrefix.length > 0); BOOL nationalPrefixIsUsedByCountry = (self.currentMetaData_.nationalPrefix && self.currentMetaData_.nationalPrefix.length > 0);
@ -473,7 +473,7 @@
for (NSUInteger i = 0; i < possibleFormatsLength; ++i) for (NSUInteger i = 0; i < possibleFormatsLength; ++i)
{ {
/** @type {i18n.phonenumbers.NumberFormat} */ /** @type {i18n.phonenumbers.NumberFormat} */
NBNumberFormat *format = [self.possibleFormats_ safeObjectAtIndex:i]; NBNumberFormat *format = [self.possibleFormats_ customSafeObjectAtIndex:i];
if (format.leadingDigitsPatterns.count == 0) { if (format.leadingDigitsPatterns.count == 0) {
// Keep everything that isn't restricted by leading digits. // Keep everything that isn't restricted by leading digits.
@ -485,7 +485,7 @@
NSInteger lastLeadingDigitsPattern = MIN(indexOfLeadingDigitsPattern, format.leadingDigitsPatterns.count - 1); NSInteger lastLeadingDigitsPattern = MIN(indexOfLeadingDigitsPattern, format.leadingDigitsPatterns.count - 1);
/** @type {string} */ /** @type {string} */
NSString *leadingDigitsPattern = [format.leadingDigitsPatterns safeObjectAtIndex:lastLeadingDigitsPattern]; NSString *leadingDigitsPattern = [format.leadingDigitsPatterns customSafeObjectAtIndex:lastLeadingDigitsPattern];
if ([self.phoneUtil_ stringPositionByRegex:leadingDigits regex:leadingDigitsPattern] == 0) { if ([self.phoneUtil_ stringPositionByRegex:leadingDigits regex:leadingDigitsPattern] == 0) {
[possibleFormats addObject:format]; [possibleFormats addObject:format];
@ -554,7 +554,7 @@
// this match will always succeed // this match will always succeed
/** @type {string} */ /** @type {string} */
NSString *aPhoneNumber = [m safeObjectAtIndex:0]; NSString *aPhoneNumber = [m customSafeObjectAtIndex:0];
// No formatting template can be created if the number of digits entered so // No formatting template can be created if the number of digits entered so
// far is longer than the maximum the current formatting rule can accommodate. // far is longer than the maximum the current formatting rule can accommodate.
if (aPhoneNumber.length < self.nationalNumber_.length) { if (aPhoneNumber.length < self.nationalNumber_.length) {
@ -1101,7 +1101,7 @@
NSString *nationalPrefixForParsing = [NSString stringWithFormat:@"^(?:%@)", self.currentMetaData_.nationalPrefixForParsing]; NSString *nationalPrefixForParsing = [NSString stringWithFormat:@"^(?:%@)", self.currentMetaData_.nationalPrefixForParsing];
/** @type {Array.<string>} */ /** @type {Array.<string>} */
NSArray *m = [self.phoneUtil_ matchedStringByRegex:nationalNumber regex:nationalPrefixForParsing]; NSArray *m = [self.phoneUtil_ matchedStringByRegex:nationalNumber regex:nationalPrefixForParsing];
NSString *firstString = [m safeObjectAtIndex:0]; NSString *firstString = [m customSafeObjectAtIndex:0];
if (m != nil && firstString != nil && firstString.length > 0) { if (m != nil && firstString != nil && firstString.length > 0) {
// When the national prefix is detected, we use international formatting // When the national prefix is detected, we use international formatting
// rules instead of national ones, because national formatting rules could // rules instead of national ones, because national formatting rules could
@ -1135,7 +1135,7 @@
/** @type {Array.<string>} */ /** @type {Array.<string>} */
NSArray *m = [self.phoneUtil_ matchedStringByRegex:accruedInputWithoutFormatting regex:internationalPrefix]; NSArray *m = [self.phoneUtil_ matchedStringByRegex:accruedInputWithoutFormatting regex:internationalPrefix];
NSString *firstString = [m safeObjectAtIndex:0]; NSString *firstString = [m customSafeObjectAtIndex:0];
if (m != nil && firstString != nil && firstString.length > 0) { if (m != nil && firstString != nil && firstString.length > 0) {
self.isCompleteNumber_ = YES; self.isCompleteNumber_ = YES;

View File

@ -8,11 +8,11 @@
#import "NBPhoneMetaData.h" #import "NBPhoneMetaData.h"
@interface NSArray (NBAdditions) @interface NSArray (NBAdditions)
- (id)safeObjectAtIndex:(NSUInteger)index; - (id)customSafeObjectAtIndex:(NSUInteger)index;
@end @end
@implementation NSArray (NBAdditions) @implementation NSArray (NBAdditions)
- (id)safeObjectAtIndex:(NSUInteger)index { - (id)customSafeObjectAtIndex:(NSUInteger)index {
@synchronized(self) { @synchronized(self) {
if (index >= [self count]) return nil; if (index >= [self count]) return nil;
id res = [self objectAtIndex:index]; id res = [self objectAtIndex:index];
@ -228,34 +228,34 @@ NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
[contents appendString:@" self = [super init];\n"]; [contents appendString:@" self = [super init];\n"];
[contents appendString:@" if (self) {\n"]; [contents appendString:@" if (self) {\n"];
/* 1 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:1] name:@"self.generalDesc"]]; /* 1 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:1] name:@"self.generalDesc"]];
/* 2 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:2] name:@"self.fixedLine"]]; /* 2 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:2] name:@"self.fixedLine"]];
/* 3 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:3] name:@"self.mobile"]]; /* 3 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:3] name:@"self.mobile"]];
/* 4 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:4] name:@"self.tollFree"]]; /* 4 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:4] name:@"self.tollFree"]];
/* 5 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:5] name:@"self.premiumRate"]]; /* 5 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:5] name:@"self.premiumRate"]];
/* 6 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:6] name:@"self.sharedCost"]]; /* 6 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:6] name:@"self.sharedCost"]];
/* 7 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:7] name:@"self.personalNumber"]]; /* 7 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:7] name:@"self.personalNumber"]];
/* 8 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:8] name:@"self.voip"]]; /* 8 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:8] name:@"self.voip"]];
/* 21 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:21] name:@"self.pager"]]; /* 21 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:21] name:@"self.pager"]];
/* 25 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:25] name:@"self.uan"]]; /* 25 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:25] name:@"self.uan"]];
/* 27 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:27] name:@"self.emergency"]]; /* 27 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:27] name:@"self.emergency"]];
/* 28 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:28] name:@"self.voicemail"]]; /* 28 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:28] name:@"self.voicemail"]];
/* 24 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata safeObjectAtIndex:24] name:@"self.noInternationalDialling"]]; /* 24 */ [contents appendString:[self phoneNumberDescWithData:[currentMetadata customSafeObjectAtIndex:24] name:@"self.noInternationalDialling"]];
/* 9 */ [contents appendFormat:@" self.codeID = %@;\n", STR_VAL([currentMetadata safeObjectAtIndex:9])]; /* 9 */ [contents appendFormat:@" self.codeID = %@;\n", STR_VAL([currentMetadata customSafeObjectAtIndex:9])];
/* 10 */ [contents appendFormat:@" self.countryCode = %@;\n", NUM_VAL([currentMetadata safeObjectAtIndex:10])]; /* 10 */ [contents appendFormat:@" self.countryCode = %@;\n", NUM_VAL([currentMetadata customSafeObjectAtIndex:10])];
/* 11 */ [contents appendFormat:@" self.internationalPrefix = %@;\n", STR_VAL([currentMetadata safeObjectAtIndex:11])]; /* 11 */ [contents appendFormat:@" self.internationalPrefix = %@;\n", STR_VAL([currentMetadata customSafeObjectAtIndex:11])];
/* 17 */ [contents appendFormat:@" self.preferredInternationalPrefix = %@;\n", STR_VAL([currentMetadata safeObjectAtIndex:17])]; /* 17 */ [contents appendFormat:@" self.preferredInternationalPrefix = %@;\n", STR_VAL([currentMetadata customSafeObjectAtIndex:17])];
/* 12 */ [contents appendFormat:@" self.nationalPrefix = %@;\n", STR_VAL([currentMetadata safeObjectAtIndex:12])]; /* 12 */ [contents appendFormat:@" self.nationalPrefix = %@;\n", STR_VAL([currentMetadata customSafeObjectAtIndex:12])];
/* 13 */ [contents appendFormat:@" self.preferredExtnPrefix = %@;\n", STR_VAL([currentMetadata safeObjectAtIndex:13])]; /* 13 */ [contents appendFormat:@" self.preferredExtnPrefix = %@;\n", STR_VAL([currentMetadata customSafeObjectAtIndex:13])];
/* 15 */ [contents appendFormat:@" self.nationalPrefixForParsing = %@;\n", STR_VAL([currentMetadata safeObjectAtIndex:15])]; /* 15 */ [contents appendFormat:@" self.nationalPrefixForParsing = %@;\n", STR_VAL([currentMetadata customSafeObjectAtIndex:15])];
/* 16 */ [contents appendFormat:@" self.nationalPrefixTransformRule = %@;\n", STR_VAL([currentMetadata safeObjectAtIndex:16])]; /* 16 */ [contents appendFormat:@" self.nationalPrefixTransformRule = %@;\n", STR_VAL([currentMetadata customSafeObjectAtIndex:16])];
/* 18 */ [contents appendFormat:@" self.sameMobileAndFixedLinePattern = %@;\n", [[currentMetadata safeObjectAtIndex:18] boolValue] ? @"YES":@"NO"]; /* 18 */ [contents appendFormat:@" self.sameMobileAndFixedLinePattern = %@;\n", [[currentMetadata customSafeObjectAtIndex:18] boolValue] ? @"YES":@"NO"];
/* 19 */ [contents appendString:[self phoneNumberFormatArrayWithData:[currentMetadata safeObjectAtIndex:19] name:@"self.numberFormats"]]; // NBNumberFormat array /* 19 */ [contents appendString:[self phoneNumberFormatArrayWithData:[currentMetadata customSafeObjectAtIndex:19] name:@"self.numberFormats"]]; // NBNumberFormat array
/* 20 */ [contents appendString:[self phoneNumberFormatArrayWithData:[currentMetadata safeObjectAtIndex:20] name:@"self.intlNumberFormats"]]; // NBNumberFormat array /* 20 */ [contents appendString:[self phoneNumberFormatArrayWithData:[currentMetadata customSafeObjectAtIndex:20] name:@"self.intlNumberFormats"]]; // NBNumberFormat array
/* 22 */ [contents appendFormat:@" self.mainCountryForCode = %@;\n", [[currentMetadata safeObjectAtIndex:22] boolValue] ? @"YES":@"NO"]; /* 22 */ [contents appendFormat:@" self.mainCountryForCode = %@;\n", [[currentMetadata customSafeObjectAtIndex:22] boolValue] ? @"YES":@"NO"];
/* 23 */ [contents appendFormat:@" self.leadingDigits = %@;\n", STR_VAL([currentMetadata safeObjectAtIndex:23])]; /* 23 */ [contents appendFormat:@" self.leadingDigits = %@;\n", STR_VAL([currentMetadata customSafeObjectAtIndex:23])];
/* 26 */ [contents appendFormat:@" self.leadingZeroPossible = %@;\n", [[currentMetadata safeObjectAtIndex:26] boolValue] ? @"YES":@"NO"]; /* 26 */ [contents appendFormat:@" self.leadingZeroPossible = %@;\n", [[currentMetadata customSafeObjectAtIndex:26] boolValue] ? @"YES":@"NO"];
[contents appendString:@" }\n"]; [contents appendString:@" }\n"];
[contents appendString:@" return self;\n"]; [contents appendString:@" return self;\n"];
@ -346,7 +346,7 @@ NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- (NSString *)phoneNumberDescWithData:(id)value - (NSString *)phoneNumberDescWithData:(id)value
{ {
NSString *initSentance = [NSString stringWithFormat:@"[[NBPhoneNumberDesc alloc] initWithNationalNumberPattern:%@ withPossibleNumberPattern:%@ withExample:%@]", NSString *initSentance = [NSString stringWithFormat:@"[[NBPhoneNumberDesc alloc] initWithNationalNumberPattern:%@ withPossibleNumberPattern:%@ withExample:%@]",
STR_VAL([value safeObjectAtIndex:2]), STR_VAL([value safeObjectAtIndex:3]), STR_VAL([value safeObjectAtIndex:6])]; STR_VAL([value customSafeObjectAtIndex:2]), STR_VAL([value customSafeObjectAtIndex:3]), STR_VAL([value customSafeObjectAtIndex:6])];
return initSentance; return initSentance;
} }
@ -359,15 +359,15 @@ NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
NSString *arrayName = [NSString stringWithFormat:@"%@_patternArray", cleanName]; NSString *arrayName = [NSString stringWithFormat:@"%@_patternArray", cleanName];
if (value != nil && [value isKindOfClass:[NSArray class]]) { if (value != nil && [value isKindOfClass:[NSArray class]]) {
/* 1 */ NSString *pattern = [value safeObjectAtIndex:1]; /* 1 */ NSString *pattern = [value customSafeObjectAtIndex:1];
/* 2 */ NSString *format = [value safeObjectAtIndex:2]; /* 2 */ NSString *format = [value customSafeObjectAtIndex:2];
/* 4 */ NSString *nationalPrefixFormattingRule = [value safeObjectAtIndex:4]; /* 4 */ NSString *nationalPrefixFormattingRule = [value customSafeObjectAtIndex:4];
/* 6 */ BOOL nationalPrefixOptionalWhenFormatting = [[value safeObjectAtIndex:6] boolValue]; /* 6 */ BOOL nationalPrefixOptionalWhenFormatting = [[value customSafeObjectAtIndex:6] boolValue];
/* 5 */ NSString *domesticCarrierCodeFormattingRule = [value safeObjectAtIndex:5]; /* 5 */ NSString *domesticCarrierCodeFormattingRule = [value customSafeObjectAtIndex:5];
[contents appendFormat:@"\n NSMutableArray *%@ = [[NSMutableArray alloc] init];\n", arrayName]; [contents appendFormat:@"\n NSMutableArray *%@ = [[NSMutableArray alloc] init];\n", arrayName];
/* 3 */ id tmpData = [value safeObjectAtIndex:3]; /* 3 */ id tmpData = [value customSafeObjectAtIndex:3];
if (tmpData != nil && [tmpData isKindOfClass:[NSArray class]]) { if (tmpData != nil && [tmpData isKindOfClass:[NSArray class]]) {
for (id numFormat in tmpData) { for (id numFormat in tmpData) {

View File

@ -7,11 +7,11 @@
#import "NBPhoneNumberDesc.h" #import "NBPhoneNumberDesc.h"
@interface NSArray (NBAdditions) @interface NSArray (NBAdditions)
- (id)safeObjectAtIndex:(NSUInteger)index; - (id)customSafeObjectAtIndex:(NSUInteger)index;
@end @end
@implementation NSArray (NBAdditions) @implementation NSArray (NBAdditions)
- (id)safeObjectAtIndex:(NSUInteger)index { - (id)customSafeObjectAtIndex:(NSUInteger)index {
@synchronized(self) { @synchronized(self) {
if (index >= [self count]) return nil; if (index >= [self count]) return nil;
id res = [self objectAtIndex:index]; id res = [self objectAtIndex:index];
@ -33,9 +33,9 @@
NSString *exp = nil; NSString *exp = nil;
if (data != nil && [data isKindOfClass:[NSArray class]]) { if (data != nil && [data isKindOfClass:[NSArray class]]) {
/* 2 */ nnp = [data safeObjectAtIndex:2]; /* 2 */ nnp = [data customSafeObjectAtIndex:2];
/* 3 */ pnp = [data safeObjectAtIndex:3]; /* 3 */ pnp = [data customSafeObjectAtIndex:3];
/* 6 */ exp = [data safeObjectAtIndex:6]; /* 6 */ exp = [data customSafeObjectAtIndex:6];
} }
return [self initWithNationalNumberPattern:nnp withPossibleNumberPattern:pnp withExample:exp]; return [self initWithNationalNumberPattern:nnp withPossibleNumberPattern:pnp withExample:exp];