不推荐使用initForReadingWithData-initForReadingFromData返回nil

时间:2019-01-11 23:08:44

标签: ios objective-c deprecated nskeyedunarchiver

我有以下警告(Xcode 10.1-iOS 12.1)

  

'initForReadingWithData:'已被弃用:首先在iOS 12.0中弃用-使用-initForReadingFromData:error:代替*

当我将方法更改为initForReadingFromData时,NSKeyedUnarchiver返回nil。

Sub CellRightMarked()
Dim DArrayRight() As Variant
Dim rcell As Range, rrow As Range
Dim r As Integer, i As Long

 For Each sht In ActiveWorkbook.Worksheets
   With sht
     Set rrow = .UsedRange
       For r = LBound(DArrayRight) To UBound(DArrayRight)
        For Each rcell In rrow
            If rcell.Value = DArrayRight(r) Then
                .Range(rcell.Offset(0, 1), rcell.Offset(0, 1)).Font.Color = 255
            End If
        Next rcell
     Next r
   End With
  Next sht
 End Sub

...

// Current code which produces the warning (but works fine) : 

NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];

NSMutableArray *loadedCredentialIdentities = (NSMutableArray *)[unarchiver decodeObjectForKey:kStoredCredentialIdentities];

[unarchiver finishDecoding];

3 个答案:

答案 0 :(得分:1)

关闭secureCoding解决了该问题。

[[NSKeyedUnarchiver alloc] initForReadingFromData:data error:&error]; unarchiver.requiresSecureCoding = NO; [取消存档的encodeObjectForKey:...]

在不必向后兼容的情况下,最好不要关闭secureCoding

答案 1 :(得分:0)

这是因为您正在使用decodeObjectForKey。如果未将requiresSecureCoding设置为NO,则必须使用decodeObjectOfClass:forKey:

答案 2 :(得分:0)

从WWDC 2018观看此视频,然后修复您的未归档者以使用安全编码: https://developer.apple.com/videos/play/wwdc2018/222/