一、约束警告

在使用Masonry的时候经常与遇到下面的警告日志

[LayoutConstraints] Unable to simultaneously satisfy constraints.

Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
****
)
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

上面的问题是由于系统判定代码和编辑器中可能出现了重复约束,可以不处理。

刚开始的时候我没有理解重复约束,因为感觉约束的没有毛病。后来才发现,因为cell的高度是根据约束变化,对于固定高度的cell,我约束了某个控件的topleftbottomrightheight,系统判定的原因可能在于已经约束了topbottom,那么对于height就没有必要约束,属于重复约束。

解决办法:设置优先级即可

make.height.mas_equalTo(75).priorityHigh();
二、方法名属性声明警告

swift和oc混编的项目中,swift使用到的oc类中会有下面的警告

Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)

因为在swift中,使用!或者?表示一个对象是optional的还是non-optional,类似view?view!。而在Objective-C中则没有这一区分,view既可表示这个对象是optional,也可表示是non-optioanl。这样就会造成一个问题:在Swift与Objective-C混编时,Swift编译器并不知道一个Objective-C对象到底是optional还是non-optional,因此这种情况下编译器会隐式地将Objective-C的对象当成是non-optional。

使用UIView * __nullable即可解决警告

三、消除注释中的警告

类似:

/**
 * @param value
 */

因为没有对value的相关描述信息,项目中会有警告提示,常见于一些第三方库和自己遗漏的代码中

解决办法:在 Build Settings 中将 Documentation Comments 的值设置为NO就不会有相关的警告提示了

四、消除方法过期(弃用)警告
// 消除方法弃用(过时)的警告
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// 要消除警告的代码
这里写出现警告的代码
#pragma clang diagnostic pop
五、消除方法没有实现的警告
// ignored(忽视)消除对应的selector的警告
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
// 要消除警告的代码
这里写出现警告的代码
// 结束
#pragma clang diagnostic pop
六、.framework或者.a库版本警告

提示如下:

ld: warning: object file (****r.o)) was built for newer iOS version (14.5) than being linked (12.1)

framework支持的最低的版本是14.5,而项目支持的最低版本是12.1。

解决方法:Build Settings -> Other Linker Flags,添加-w即可

七、other

消除pod内的警告(pod库的注释警告请看第三点):

# 忽略引入库的所有警告
inhibit_all_warnings!

关于pod库还会有如下提示:

The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99.

因为项目最低支持的版本号高于pod库依赖的最低版本号,在podfile加入:

# 忽略引入库版本警告
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
    end
  end
end

版本与platform :ios, '10.0'一直即可!

其它的warning的消除大致就一些过期方法、过期类。该删除的删除,该换新的换新的!类似UIAlertViewUIActionSheet等。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐