Closed maulikshah09 closed 4 years ago
Got it...Localization issue.. if not localize then work perfectly .How can i Solve this.. I know it's localisation issue..
calling this mehod...Bundle.setLanguage("ar") or Bundle.setLanguage("en")
import Foundation
import ObjectiveC
import UIKit
var kBundleKey: UInt8 = 0
var isLangDirectionRTL = false
class BundleEx: Bundle {
override func localizedString(forKey key: String, value: String?, table tableName: String?) -> String {
let bundle: Bundle? = objc_getAssociatedObject(self, &kBundleKey) as? Bundle
if bundle != nil {
return NSLocalizedString(value!, tableName: nil, bundle: bundle!, value: "", comment: "")
}
else {
return super.localizedString(forKey: key, value: value, table: tableName)
}
}
}
extension Bundle {
class func setLanguage(_ language: String?) {
var onceToken = 0
if (onceToken == 0) {
/* TODO: move below code to a static variable initializer (dispatch_once is deprecated) */
object_setClass(Bundle.main, BundleEx.self)
}
UserDefaults.standard.set(language, forKey: UserDefaultKey.AppleLanguage.rawValue)
UserDefaults.standard.synchronize()
onceToken = 1
let isLanguageRTL: Bool = self.isLanguageRTL(language)
if isLanguageRTL {
isLangDirectionRTL = true
if UIView().responds(to: #selector(setter: UIView.semanticContentAttribute)) {
UIView.appearance().semanticContentAttribute = .forceRightToLeft
}
}
else {
isLangDirectionRTL = false
if UIView().responds(to: #selector(setter: UIView.semanticContentAttribute)) {
UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
}
// UserDefaults.standard.set(isLanguageRTL, forKey: "AppleTextDirection")
// UserDefaults.standard.set(isLanguageRTL, forKey: "NSForceRightToLeftWritingDirection")
// UserDefaults.standard.synchronize()
let value = Bundle(path: Bundle.main.path(forResource: language, ofType: "lproj") ?? "")
objc_setAssociatedObject(Bundle.main, &kBundleKey, value, .OBJC_ASSOCIATION_RETAIN)
}
class func isLanguageRTL(_ languageCode: String?) -> Bool {
return NSLocale.characterDirection(forLanguage: languageCode ?? "") == .rightToLeft
}
}
Hi. as I can see it caused by outside changes.
I belive you have to set not nil argument as it says: 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'
add pod pod 'ActionSheetPicker-3.0'
goto terminal and pod install from terminal
import ActionSheetPicker_3_0
copy paste code.
and crash what is the issue.Don't know.
'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'