gpt4 book ai didi

objective-c - 默认情况下,Objective-C 函数结果是否为非空?

转载 作者:搜寻专家 更新时间:2023-10-30 20:08:30 28 4
gpt4 key购买 nike

this thread在实现 UITextInput 委托(delegate)方法时,发布者说,当他们对代码运行静态分析时,他们在这个函数上遇到错误:

- (NSArray *)selectionRectsForRange:(UITextRange *)range
{
return nil;
}

错误是“从预期返回非空值的方法返回 nil。”

函数声明在结果上没有可空性说明符。默认情况下函数结果是否非空? (这些天我主要在 Swift 工作,对 Objective-C 的最新变化不是专家。)

最佳答案

他们不是。

声明该方法的 header 用 the "assume nonnull" macros 括起来:

//
// UITextInput.h
// UIKit
//
// Copyright (c) 2009-2017 Apple Inc. All rights reserved.
//

#import <CoreGraphics/CoreGraphics.h>

#import <UIKit/UITextInputTraits.h>
#import <UIKit/UIResponder.h>

//===================================================================================================
// Responders that implement the UIKeyInput protocol will be driven by the system-provided keyboard,
// which will be made available whenever a conforming responder becomes first responder.

NS_ASSUME_NONNULL_BEGIN

// snip
// ...
// L150
/* Geometry used to provide, for example, a correction rect. */
- (CGRect)firstRectForRange:(UITextRange *)range;
- (CGRect)caretRectForPosition:(UITextPosition *)position;
- (NSArray *)selectionRectsForRange:(UITextRange *)range NS_AVAILABLE_IOS(6_0); // Returns an array of UITextSelectionRects

所以这个方法实际上已经被标记为具有非空返回值。

关于objective-c - 默认情况下,Objective-C 函数结果是否为非空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45928639/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com