首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在可快速解码模型对象中添加新属性的App崩溃

在可快速解码模型对象中添加新属性的App崩溃
EN

Stack Overflow用户
提问于 2022-08-07 12:55:41
回答 1查看 176关注 0票数 1

下面是我的示例代码。一切都很完美,但是如果试图在PageLoadTestDetailResponseModel结构中添加一个新的属性,那么应用程序就会崩溃。API响应和解析没有问题。在print语句中获取解析的值。根据崩溃日志,这是与内存有关的东西,但我无法弄清楚。下面是我的示例代码。我的API响应大约是40 KB。请帮帮我。

Note-

  1. I并不是只会消耗响应对象。如果将PageLoadstruct更改为class应用程序,则
  2. 不会破坏

代码语言:javascript
复制
import RxCocoa
import RxSwift

public struct TestDetailViewModel {
    
    private func getTestDetailSuccessResponse() -> Driver<TestDetailResponseModel?> {
        
        //Make API call asynchronously using RxSwift and storing result in testDetailResponseModel
         let testDetailResponseModel: TestDetailResponseModel? = RXNetworkManager.execute(request: MyRequestModel) {

        //Api Response
        //Parse response. Parsing is proper. responseModel prints all the parsed properties with correct values of TestDetailResponseModel and PageLoad objects (detail, and pageNumber)
        print(responseModel)
        }
        return Driver.just(testDetailResponseModel)
    }
    
    private func loadDetail() {
        let isDetailExist = getTestDetailSuccessResponse().compactMap { response -> Bool? in
            print(response) //No Crash
            print(response?.pageLoad) //App crashed here if add pageNumber property in PageLoad object
            return response?.pageLoad != nil
        }
    }
}

public struct TestDetailResponseModel: Decodable {
    public let pageLoad: PageLoad?
    //...
}

public struct PageLoad: Decodable {
    public let detail: String?
    //...
    public let pageNumber: Double? //New property
}

=================Crash same====================报告

代码语言:javascript
复制
Exception Type:  EXC_BAD_ACCESS (SIGABRT)
Exception Subtype: KERN_INVALID_ADDRESS at 0x50a01fb550981f18 -> 0xffff9fb550981f18 (possible pointer authentication failure)
Exception Codes: 0x0000000000000001, 0x50a01fb550981f18
VM Region Info: 0xffff9fb550981f18 is not in any region.  Bytes after previous region: 18446532646169747225
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_NANO (reserved)   600018000000-600020000000 [128.0M] rw-/rwx SM=NUL  ...(unallocated)
--->
      UNUSED SPACE AT END
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Application Specific Information:
=================================================================
==17015==ERROR: AddressSanitizer: SEGV on unknown address 0x50a01fb550981f18 (pc 0x00018f9e1d50 bp 0x00016bbf60c0 sp 0x00016bbf6080 T0)
==17015==The signal is caused by a UNKNOWN memory access.
#0 0x18f9e1d50 in swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int)+0x2c (libswiftCore.dylib:arm64+0x302d50)
#1 0x18f9b20bc in _swift_retain_+0x54 (libswiftCore.dylib:arm64+0x2d30bc)
#2 0x10d8d5edc  (liboainject.dylib:arm64+0x5edc)
#3 0x18f9e7958 in swift_bridgeObjectRetain+0x30 (libswiftCore.dylib:arm64+0x308958)
#4 0x1191ab100 in outlined copy of PageLoad?+0x1dc (TestCore:arm64+0x10ff100)
#5 0x1196cf554 in outlined copy of TestDetailResponseModel?+0x6a4 (TestCore:arm64+0x1623554)
#6 0x11a1541bc in TestDetailViewModel.getTestDetailSuccessResponse(response:) TestDetailViewModel+APICalls.swift:69
#7 0x1195240b8 in closure #13 in TestDetailViewModel.transform(input:) TestDetailViewModel.swift:108
#8 0x10e59b30c in CompactMapSink.on(_:) CompactMap.swift:47
#9 0x10e59b550 in protocol witness for ObserverType.on(_:) in conformance CompactMapSink<A, B> <compiler-generated>
#10 0x10e5f91d0 in partial apply for implicit closure #2 in implicit closure #1 in ShareWhileConnectedConnection._synchronized_subscribe<A>(_:) <compiler-generated>
#11 0x10e58d8d8 in thunk for @escaping @callee_guaranteed (@in_guaranteed Event<A>) -> () <compiler-generated>
#12 0x10e5f804c in ShareReplay1WhileConnectedConnection.on(_:)+0x70 (RxSwift:arm64+0x8804c)
#13 0x10e5f7bf4 in protocol witness for ObserverType.on(_:) in conformance ShareReplay1WhileConnectedConnection<A> <compiler-generated>
#14 0x10e5b0514 in Sink.forwardOn(_:) Sink.swift:34
#15 0x10e582398 in SwitchSinkIter._synchronized_on(_:) Switch.swift:160
#16 0x10e5abb68 in SynchronizedOnType.synchronizedOn(_:) SynchronizedOnType.swift:16
#17 0x10e582488 in protocol witness for ObserverType.on(_:) in conformance SwitchSinkIter<A, B, C> <compiler-generated>
#18 0x10e5f91d0 in partial apply for implicit closure #2 in implicit closure #1 in ShareWhileConnectedConnection._synchronized_subscribe<A>(_:) <compiler-generated>
#19 0x10e58d8d8 in thunk for @escaping @callee_guaranteed (@in_guaranteed Event<A>) -> () <compiler-generated>
#20 0x10e5f804c in ShareReplay1WhileConnectedConnection.on(_:)+0x70 (RxSwift:arm64+0x8804c)
#21 0x10e5f7bf4 in protocol witness for ObserverType.on(_:) in conformance ShareReplay1WhileConnectedConnection<A> <compiler-generated>
#22 0x10e5b0514 in Sink.forwardOn(_:) Sink.swift:34
#23 0x10e59d0c8 in CatchSink.on(_:) Catch.swift:131
#24 0x10e59d31c in protocol witness for ObserverType.on(_:) in conformance CatchSink<A> <compiler-generated>
#25 0x10e605534 in closure #1 in ObserveOnSerialDispatchQueueSink.init(scheduler:observer:cancel:) ObserveOn.swift:184
#26 0x10e605d48 in partial apply for thunk for @escaping @callee_guaranteed (@guaranteed ObserveOnSerialDispatchQueueSink<A>, @in_guaranteed Event<A.ObserverType.Element>) -> (@out Disposable) <compiler-generated>
#27 0x10e5904e4 in partial apply for closure #1 in MainScheduler.scheduleInternal<A>(_:action:) <compiler-generated>
#28 0x10e585410 in thunk for @escaping @callee_guaranteed () -> () <compiler-generated>
#29 0x1139f950c in __wrap_dispatch_async_block_invoke+0xb8 (libclang_rt.asan_iossim_dynamic.dylib:arm64+0x3d50c)
#30 0x18010d240 in _dispatch_call_block_and_release+0x14 (libdispatch.dylib:arm64+0x2240)
#31 0x18010ea94 in _dispatch_client_callout+0xc (libdispatch.dylib:arm64+0x3a94)
#32 0x18011c418 in _dispatch_main_queue_drain+0x3cc (libdispatch.dylib:arm64+0x11418)
#33 0x18011c038 in _dispatch_main_queue_callback_4CF+0x24 (libdispatch.dylib:arm64+0x11038)
#34 0x180361c28 in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__+0x8 (CoreFoundation:arm64+0x85c28)
#35 0x18035c0ac in __CFRunLoopRun+0x97c (CoreFoundation:arm64+0x800ac)
#36 0x18035b214 in CFRunLoopRunSpecific+0x238 (CoreFoundation:arm64+0x7f214)
#37 0x18c25f608 in GSEventRunModal+0x9c (GraphicsServices:arm64+0x3608)
#38 0x184d88a94 in -[UIApplication _run]+0x3dc (UIKitCore:arm64+0xc0da94)
#39 0x184d8d630 in UIApplicationMain+0x6c (UIKitCore:arm64+0xc12630)
#40 0x104dc5958 in main AppDelegate.swift:32
#41 0x10b66dcd4 in start_sim+0x10 (dyld_sim:arm64+0x1cd4)
#42 0x10b71d084  (<unknown module>)
#43 0xa777ffffffffffc  (<unknown module>)
==17015==Register values:
x[0] = 0x000000018035ba08   x[1] = 0xaa1403f6aa1303e1   x[2] = 0x0000000000000001   x[3] = 0x0000000000000001
x[4] = 0x0000000000000000   x[5] = 0x0000000000000000   x[6] = 0x0000000000000000   x[7] = 0x0000000000000000
x[8] = 0x50a01fb550981f08   x[9] = 0x000000018035ba00  x[10] = 0xffffffffffffffff  x[11] = 0xaa1403f8aa1303e1
x[12] = 0x0000000000000000  x[13] = 0x0000000000000000  x[14] = 0x0000000000000000  x[15] = 0x0000000000000000
x[16] = 0x00000001cc0ac98c  x[17] = 0x0000000000000000  x[18] = 0x0000000000000000  x[19] = 0x000000016bbf6118
x[20] = 0x000000018035ba00  x[21] = 0x000000010d8dc000  x[22] = 0x000000016bbf60f8  x[23] = 0x000000010d8dc000
x[24] = 0x000000010d8dc000  x[25] = 0x0000000000000000  x[26] = 0x40c1d7097c1bda51  x[27] = 0x4000000153eb88d0
x[28] = 0xc000000000000030     fp = 0x000000016bbf60c0     lr = 0x000000018f9b20c0     sp = 0x000000016bbf6080
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (libswiftCore.dylib:arm64+0x302d50) in swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int)+0x2c
==17015==ABORTING
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode_13.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_INSERT_LIBRARIES=/Applications/Xcode_13.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/DVTInstrumentsFoundation.framework/liboainject.dylib
CoreSimulator 802.6.1 - Device: iPhone 13 Pro Max (********-****-****-****-************) - Runtime: iOS 15.5 (19F70) - DeviceType: iPhone 13 Pro Max
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode_13.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_INSERT_LIBRARIES=/Applications/Xcode_13.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/DVTInstrumentsFoundation.framework/liboainject.dylib
abort() called


Kernel Triage:
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
EN

回答 1

Stack Overflow用户

发布于 2022-08-07 13:19:54

没有多少信息,但我能猜到问题出在哪里

任何Api调用异步,您都需要对dataTask的句柄结果使用@转义完成。

代码语言:javascript
复制
private func getTestDetailSuccessResponse(completion: @escaping (TestDetailResponseModel>)->Void) {
    var testDetailResponseModel: TestDetailResponseModel?

    // Make api call
    // return result of call into completion as "completion(result)"
}

使用:

代码语言:javascript
复制
private func loadDetail() {
    getTestDetailSuccessResponse { result in
        let detail = result?.pageLoad
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73267608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档