Input-mask-ios: 12.2 ๊ฐœ๋ฐœ์ž ๋ฒ ํƒ€ 2 ์ถฉ๋Œ - initWithCoder ์˜ค๋ฅ˜

์— ๋งŒ๋“  2019๋…„ 02์›” 15์ผ  ยท  11์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: RedMadRobot/input-mask-ios

์ „์ œ ์กฐ๊ฑด

  • [X ] ๋‹ค์Œ์„ ๋ชจ๋‘ ์ˆ˜ํ–‰ํ•œ ๊ฒฝ์šฐ ์ด ์ค„์˜ ๋Œ€๊ด„ํ˜ธ ์‚ฌ์ด์— X ๋„ฃ์œผ์‹ญ์‹œ์˜ค.

    • ์šฐ๋ฆฌ ์œ„ํ‚ค ์ฝ๊ธฐ ;

    • ์•Œ๋ ค์ง„ ๋ฌธ์ œ ์„น์…˜ ์ „์ฒด๋ฅผ ์ฝ์œผ์‹ญ์‹œ์˜ค.

    • ๋‚ด ๋ฌธ์ œ๊ฐ€ ์•„์ง ์ฑ„์›Œ ์ง€์ง€ ์•Š์•˜๋Š”์ง€ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.

    • ๋น„์Šทํ•œ ๋ฌธ์ œ์— ๋Œ€ํ•ด StackOverflow์˜ input-mask ํƒœ๊ทธ๋ฅผ ๊ฒ€์ƒ‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ฒ„๊ทธ ์„ค๋ช…

์ž…๋ ฅ ๋งˆ์Šคํฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ TextField๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ViewController๋ฅผ ์‚ฌ์šฉํ•œ ํ›„ ์•ฑ์ด ์ถฉ๋Œํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋‚˜ํƒ€๋‚ฌ์Šต๋‹ˆ๋‹ค. ๊ทธ ์ •ํ™•ํ•œ ํŽ˜์ด์ง€๊ฐ€ ์ „๋‚  ์ž‘๋™ํ–ˆ๊ณ  ์Šคํ† ๋ฆฌ๋ณด๋“œ์—์„œ ํ•ด๋‹น ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋‚˜ UI๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์€ ์ด์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‚ด๊ฐ€ ํ•œ ์œ ์ผํ•œ ๋ณ€๊ฒฝ์€ ๋‚ด ํ™˜๊ฒฝ์ด์—ˆ์Šต๋‹ˆ๋‹ค. iOS 12.2 ๊ฐœ๋ฐœ์ž ๋ฒ ํƒ€ 2์˜ ๋ฒ ํƒ€ ๋ฒ„์ „์„ ์‹คํ–‰ํ•˜๋Š” ๋‚ด ์•„์ดํฐ์—์„œ ์•ฑ์„ ์‹คํ–‰/ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ ํŽ˜์ด์ง€์—์„œ ๋ชจ๋“  ์ปจํŠธ๋กค์„ ํ•˜๋‚˜์”ฉ ๊ฐ€์ ธ์™€์„œ ์–ธ์ œ ์‹คํ–‰๋˜๋Š”์ง€ ํ™•์ธํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๊ตฌ์ถ•ํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. break - InputMask Delegate Objects๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ์ˆœ๊ฐ„์—๋งŒ ๊นจ์กŒ์Šต๋‹ˆ๋‹ค.

ํ–‰๋™์„ ์žฌํ˜„ํ•˜๋Š” ๋‹จ๊ณ„:

InputMask Textfield ์„ค์ •์ด ์žˆ๋Š” ํŽ˜์ด์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค - iOS 12.2 ๊ฐœ๋ฐœ์ž ๋ฒ ํƒ€ 2์šฉ ์•ฑ ๋นŒ๋“œ(xCode 10 ๋ฒ ํƒ€ 2 ์‚ฌ์šฉ)

์˜ˆ์ƒ๋˜๋Š” ํ–‰๋™
์ž…๋ ฅ ๋งˆ์Šคํฌ ๊ธฐ๋Šฅ

์‹ค์ œ ํ–‰๋™
์•ฑ ์ถฉ๋Œ: ์˜ค๋ฅ˜ ์ƒ์„ฑ:
Terminating app due to uncaught exception 'NSGenericException', reason: 'This coder requires that replaced objects be returned from initWithCoder:'

์ด๊ฒƒ์ด ๋ฌธ์ œ์˜ ํ•ต์‹ฌ์ด์ง€๋งŒ ๋‚˜๋จธ์ง€ ์˜ค๋ฅ˜ ํ˜ธ์ถœ ์Šคํƒ์€ ์—ฌ๊ธฐ์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

*** First throw call stack: ( 0 CoreFoundation 0x0000000108ca072b __exceptionPreprocess + 331 1 libobjc.A.dylib 0x000000010768eac5 objc_exception_throw + 48 2 CoreFoundation 0x0000000108ca0585 +[NSException raise:format:] + 197 3 UIFoundation 0x000000010f47e89c UINibDecoderDecodeObjectForValue + 827 4 UIFoundation 0x000000010f47eaf9 UINibDecoderDecodeObjectForValue + 1432 5 UIFoundation 0x000000010f47e554 -[UINibDecoder decodeObjectForKey:] + 251 6 UIKitCore 0x0000000111825e90 -[UIViewController initWithCoder:] + 1021 7 DumaPay Consumer iOS 0x00000001055bde66 $s20DumaPay_Consumer_iOS25TestAddCardViewControllerC5coderACSgSo7NSCoderC_tcfc + 2214 8 DumaPay Consumer iOS 0x00000001055bdf2f $s20DumaPay_Consumer_iOS25TestAddCardViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 47 9 UIKitCore 0x0000000111aaae89 -[UIClassSwapper initWithCoder:] + 246 10 UIFoundation 0x000000010f47e852 UINibDecoderDecodeObjectForValue + 753 11 UIFoundation 0x000000010f47e554 -[UINibDecoder decodeObjectForKey:] + 251 12 UIKitCore 0x0000000111aaf4d1 -[UIRuntimeConnection initWithCoder:] + 178 13 UIFoundation 0x000000010f47e852 UINibDecoderDecodeObjectForValue + 753 14 UIFoundation 0x000000010f47eaf9 UINibDecoderDecodeObjectForValue + 1432 15 UIFoundation 0x000000010f47e554 -[UINibDecoder decodeObjectForKey:] + 251 16 UIKitCore 0x0000000111aacd81 -[UINib instantiateWithOwner:options:] + 1216 17 UIKitCore 0x0000000111fc5290 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 181 18 DumaPay Consumer iOS 0x0000000105623ea9 $s20DumaPay_Consumer_iOS28AddCardScannerViewControllerC010goToManualfE004cardG6ResultySo0b15CardsRecognizerN0CSg_tF + 249 19 DumaPay Consumer iOS 0x0000000105623d2e $s20DumaPay_Consumer_iOS28AddCardScannerViewControllerC02oneF15ManuallyClicked6senderyyp_tF + 62 20 DumaPay Consumer iOS 0x0000000105623d8c $s20DumaPay_Consumer_iOS28AddCardScannerViewControllerC02oneF15ManuallyClicked6senderyyp_tFTo + 76 21 UIKitCore 0x0000000111e2e834 -[UIApplication sendAction:to:from:forEvent:] + 83 22 UIKitCore 0x00000001118845b5 -[UIControl sendAction:to:forEvent:] + 67 23 UIKitCore 0x00000001118848d2 -[UIControl _sendActionsForEvents:withEvent:] + 450 24 UIKitCore 0x0000000111883888 -[UIControl touchesEnded:withEvent:] + 583 25 UIKitCore 0x0000000111e6751e -[UIWindow _sendTouchesForEvent:] + 2547 26 UIKitCore 0x0000000111e68c02 -[UIWindow sendEvent:] + 4079 27 UIKitCore 0x0000000111e47346 -[UIApplication sendEvent:] + 356 28 UIKitCore 0x0000000111f178c3 __dispatchPreprocessedEventFromEventQueue + 3232 29 UIKitCore 0x0000000111f1a1e9 __handleEventQueueInternal + 5911 30 CoreFoundation 0x0000000108c07c11 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 31 CoreFoundation 0x0000000108c07493 __CFRunLoopDoSources0 + 243 32 CoreFoundation 0x0000000108c01b4f __CFRunLoopRun + 1231 33 CoreFoundation 0x0000000108c01332 CFRunLoopRunSpecific + 626 34 GraphicsServices 0x000000010f1222fe GSEventRunModal + 65 35 UIKitCore 0x0000000111e2d1d2 UIApplicationMain + 140 36 DumaPay Consumer iOS 0x0000000105609bdb main + 75 37 libdyld.dylib 0x000000010a883861 start + 1 38 ??? 0x0000000000000001 0x0 + 1 )

ํ”Œ๋žซํผ ์ •๋ณด

  • OS ๋ฒ„์ „: iOS 12.2 ๋ฒ ํƒ€ 2
  • ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฒ„์ „: 4.1.0
  • ์–ธ์–ด: ์Šค์œ„ํ”„ํŠธ 4.2

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์•„์ง ์—…๋ฐ์ดํŠธ๊ฐ€ ์—†์Šต๋‹ˆ๊นŒ?

๋ชจ๋“  11 ๋Œ“๊ธ€

์•ˆ๋…•ํ•˜์„ธ์š” @SteynMarnus ,
์ข‹์€ ์บ์น˜! ๋ชจ๋“  ๋””๋ฒ„๊ทธ ์ •๋ณด์— ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

์ตœ์‹  Xcode-beta Sample ๋ฅผ ์‹คํ–‰ํ•ด ๋ณด์•˜๋Š”๋ฐ ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์‚ดํŽด๋ณด๊ณ  ์กฐ์‚ฌ ๊ฒฐ๊ณผ๋ฅผ ๊ณต์œ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์•ˆ๋…•ํ•˜์„ธ์š” @SteynMarnus ,
์ข‹์€ ์บ์น˜! ๋ชจ๋“  ๋””๋ฒ„๊ทธ ์ •๋ณด์— ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

์ตœ์‹  Xcode-beta Sample ๋ฅผ ์‹คํ–‰ํ•ด ๋ณด์•˜๋Š”๋ฐ ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์‚ดํŽด๋ณด๊ณ  ์กฐ์‚ฌ ๊ฒฐ๊ณผ๋ฅผ ๊ณต์œ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค! ๋ฒ ํƒ€๋Š” ์•ฝ๊ฐ„ '์™€์ผ๋“œ ์›จ์ŠคํŠธ'์ž…๋‹ˆ๋‹ค. ์กฐ์‚ฌํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ข‹์•„, ์–ด๋–ป๊ฒŒ ๋“  ๋‚˜๋Š” ๊ทธ๊ฒƒ์„ ๋†“์ณค๋‹ค.
์—ฌ๊ธฐ ์—์„œ ์•Œ๋ ค์ง„ ๋ฌธ์ œ 2๋ฒˆ:

Swift ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๊ฐ€ ์ฐจ์ง€ํ•˜๋Š” ํฌ๊ธฐ๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด Swift์— ์ •์˜๋œ ํŽธ์˜ ์ด๋‹ˆ์…œ๋ผ์ด์ €๋Š” ์ด์ œ Objective-C์— ์ •์˜๋œ ์ง€์ •๋œ ์ด๋‹ˆ์…œ๋ผ์ด์ €๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒฝ์šฐ์—๋งŒ ๋ฏธ๋ฆฌ ๊ฐ์ฒด๋ฅผ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ์ด๊ฒƒ์€ ํ”„๋กœ๊ทธ๋žจ์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์ง€๋งŒ, Objective-C์—์„œ ํŽธ์˜ ์ด๋‹ˆ์…œ๋ผ์ด์ €๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด +alloc์˜ ์ดˆ๊ธฐ ํ• ๋‹น์ด ์ด๋‹ˆ์…œ๋ผ์ด์ €๊ฐ€ ํ˜ธ์ถœ๋˜์ง€ ์•Š๊ณ  ํ•ด์ œ๋ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ alloc/init ์‹œํ€€์Šค ์ข…์†์„ฑ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. _๋‹ค์‹œโ€ฆ_

์ด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜๋Š” ๋™์•ˆ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€

public override convenience init() {
    // Interface Builder support
    self.init(primaryFormat: "")
}

~์™€ ํ•จ๊ป˜

public override init() {
    // Interface Builder support
    self.primaryMaskFormat = ""
    self.autocomplete = true
    self.autocompleteOnFocus = true
    self.rightToLeft = false
    self.affineFormats = []
    self.affinityCalculationStrategy = .wholeString
    self.customNotations = []
    self.onMaskedTextChangedCallback = nil
    super.init()
}

๊ณต์‹ Swift 5 ๋ฆด๋ฆฌ์Šค๊นŒ์ง€ ์ด๊ฒƒ์„ ์—ด์–ด ๋‘๋„๋ก ํ•ฉ์‹œ๋‹ค.

์˜ค, ๋ฉ‹์ง€ ๊ตฐ์š” @taflanidi , MaskedTextViewDelegate.swift ํŒŒ์ผ์—์„œ ์ด๊ฒƒ์„ ๊ต์ฒดํ•ด์•ผ ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. ๋งž์Šต๋‹ˆ๊นŒ?

@SteynMarnus ๋‹น์‹ ์—๊ฒŒ ๋งž๋Š” ๋ฌด์—‡์ด๋“ . ํŒ€ ๊ทœ๋ชจ์— ๋”ฐ๋ผ ์ž์ฒด ํฌํฌ๋ฅผ ๋„์ž…ํ•˜๊ฑฐ๋‚˜ ์Šค์Šค๋กœ ์ž‘์—…ํ•˜๋Š” ๊ฒฝ์šฐ ํฌ๋“œ ์ž์ฒด์—์„œ ํ•ด๋‹น ๋ผ์ธ์„ ๊ต์ฒดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๋‚˜๋ณด๋‹ค ๋” ์ž˜ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๋‚˜๋Š” ์•„์ง ๊ทธ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ๋„ฃ๊ณ  ์‹ถ์ง€

UPD. MaskedTextFieldDelegate MaskedTextViewDelegate ์•„๋‹Œ MaskedTextFieldDelegate ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ๋‘˜ ๋‹ค ๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ด
์˜ค๋Š˜ Xcode 10.2๊ฐ€ ์ถœ์‹œ๋˜์—ˆ์œผ๋ฉฐ ์ด ๋ฒ„๊ทธ๋Š” ์—ฌ์ „ํžˆ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

@taflanidi ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์ด ๋„์›€์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

@sashaBizquit ๊ฐ„๋‹จํžˆ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค.
swift required public init?(coder aDecoder: NSCoder) { // Interface Builder support self.primaryMaskFormat = "" self.autocomplete = true self.autocompleteOnFocus = true self.rightToLeft = false self.affineFormats = [] self.affinityCalculationStrategy = .wholeString self.customNotations = [] self.onMaskedTextChangedCallback = nil super.init() } public override init() { // Interface Builder support self.primaryMaskFormat = "" self.autocomplete = true self.autocompleteOnFocus = true self.rightToLeft = false self.affineFormats = [] self.affinityCalculationStrategy = .wholeString self.customNotations = [] self.onMaskedTextChangedCallback = nil super.init() }
๋•Œ๋กœ๋Š”์ด ๊ต์ฒด ํ›„ ๋นŒ๋“œ๋ฅผ ์ฒญ์†Œํ•ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์•ˆ๋…•ํ•˜์„ธ์š” @sashaBizquit , ์•ˆ๋…•ํ•˜์„ธ์š” @Rik626!
์‹ ๊ณ ํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฒˆ ์ฃผ ํ›„๋ฐ˜์— ํŒจ์น˜๊ฐ€ ์ง„ํ–‰๋  ์˜ˆ์ •์ด๋‹ˆ ๋งŽ์€ ๊ด€์‹ฌ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

์ด ๋ฌธ์ œ์— ๋Œ€ํ•œ ์—…๋ฐ์ดํŠธ๊ฐ€ ์žˆ์Šต๋‹ˆ๊นŒ?

์•„์ง ์—…๋ฐ์ดํŠธ๊ฐ€ ์—†์Šต๋‹ˆ๊นŒ?

์ž, ์•„์ง ๋‹ค๋ฅธ Swift 5 ๊ด€๋ จ ๋ฒ„๊ทธ๊ฐ€ ์žˆ์–ด์„œ ๋ชจ๋“  ๊ฒƒ์ด ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์ถ”๊ฐ€๋กœ ์กฐ์‚ฌํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ ธ์Šต๋‹ˆ๋‹ค.

4.1.1 ๋Œ€๋ฅผ ๋งŒ๋‚˜๋ณด์„ธ์š”.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰