问题
Override 子类的便利初始化程序,它会产生编译错误.
详情
我有问题理解为什么Swift(v4.1)不允许我覆盖我的便利初始化器.阅读文档我发现这两条规则适用于我的问题:
规则1如果您的子类没有定义任何指定的初始值设定项,它会自动继承其所有超类指定的初始值设定项.
规则2如果您的子类提供了所有超类指定初始值设定项的实现 - 通过按照规则1继承它们,或者通过提供自定义实现作为其定义的一部分 - 那么它会自动继承所有超类便捷初始值设定项.
在下面的代码中,我属于第一个规则,我的所有便利初始化程序都被继承ClassB.此外,由于我按照规则1继承了所有指定的初始化程序,因此我也继承了所有便利初始化程序.
class ClassA<T> {
// This array would be private and not visible from ClassB
var array: [T]?
init() { }
convenience init(array: [T]) {
self.init()
self.array = array
}
}
class ClassB<T>: ClassA<T> {
var anotherArray: [T]?
// I feel like I should include the "override" keyword
// but I get a compiler error when "override" is added before "convenience init".
convenience init(array: [T]) {
self.init() …Run Code Online (Sandbox Code Playgroud) 我先退出Xcode并手动将.xcworkspace文件从更改old_name.xcworkspace为new_name.xcworkspace.它似乎工作.但这是在Xcode 5中更改工作区名称的正确方法吗?
在用C语言编写的程序的加载数据部分中,我看到缓冲区的初始化是这样完成的:
char buffer[100] = {0, };
Run Code Online (Sandbox Code Playgroud)
但是我不确定这个陈述赋予了什么值.请分享一些想法.
这取决于编译器还是语言功能?
如果此语句等效于以下,那么在该零之后使用逗号的重点是什么:
char buffer[100] = {0};
Run Code Online (Sandbox Code Playgroud)
是不是因为编码器只想确保第一个元素为零,而不关心其余元素?
想要知道整个字符集,其字符必须在Objective-C NSString对象中"进行转义才能被正确识别,例如必须进行转义\",如
NSString *temporaryString = @"That book is dubbed as \"the little book\".";
Run Code Online (Sandbox Code Playgroud)
字符集是否与C语言char *字符串中的字符集相同?
谢谢你的帮助:D
我有一个NSString对象,
NSString *aString;
Run Code Online (Sandbox Code Playgroud)
那么以下两个版本是等价的吗?
版本1:
if ( (NSString *)[NSNull null] == aString )
{
// Logic handling
}
Run Code Online (Sandbox Code Playgroud)
版本2:
if ( nil == aString )
{
// Logic handling
}
Run Code Online (Sandbox Code Playgroud)
我的简单测试结果表明上述两个版本有不同的行为:
何时aString初始化然后分配nil:
false 在版本1中表达,
true 在版本2中表达.
何时aString使用值初始化@"".
false 在版本1中表达,
false 在版本2中表达.
所以很明显,这两个版本的行为并不相同.
测试代码:
NSString *aString = nil;
NSString *bString = [NSString stringWithFormat:@""];
if ((NSString *)[NSNull null] == aString) {
NSLog(@"a1 - …Run Code Online (Sandbox Code Playgroud) 例如,
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
[rotate setToValue:@(M_PI)];
[rotate setDuration:0.1f];
[[aView layer] addAnimation:rotate forKey:@"myRotationAnimation"];
Run Code Online (Sandbox Code Playgroud)
在哪里M_PI定义为宏math.h,
#define M_PI 3.14159265358979323846264338327950288 /* pi */
Run Code Online (Sandbox Code Playgroud) 我目前正在考虑优化项目的编译时间.我一直都知道有类似于整个模块优化的东西但是在构建设置中没有检查它我没有真正深入研究它.
据我了解:
WMO应该导致更快的执行代码,但可以稍微增加编译时间,因为将整个模块文件编译为一个整体而不是并行地单独编译每个文件. https://swift.org/blog/whole-module-optimizations/
所以建议设置Swift优化级别:
None [-Onone]Fast, Whole Module Optimization [-O -whole-module-optimization]
因为对于偶尔的发布版本而言,拥有最佳编译时间并不重要但是在研究减少调试配置编译时间的一些技巧时,我发现了这个用户自定义设置:
SWIFT_WHOLE_MODULE_OPTIMIZATION = YES (用于调试)SWIFT_WHOLE_MODULE_OPTIMIZATION = NO (发布)这个设置减少了我的DEBUG编译时间差不多一半,但它也让我感到困惑.我无法找到有关此设置及其来源的任何文档. (我对swift编译器的理解非常基础,之前我没有使用过用户定义的设置)
每个人都建议它减少编译时间而不解释原因,或者解释不会与上面提到的Swift优化级别冲突.
据我了解,这个设置为YES的设置应该会增加编译时间,因为它看起来启用了wmo.因此,我认为我对wmo的理解,或者这个特定的设置是错误的.
所以我的问题是:
SWIFT_WHOLE_MODULE_OPTIMIZATION设置和有YES什么
区别?
为什么Swift Optimization Level减少编译时间?
谢谢!
Xcode Build Settings中的Alternative Install Permissions是什么意思?
Xcode 版本
从 4.6.2 (4H1003) 到 11.2.1 (11B500)。
当
目标- >生成设置- >部署- >替代安装权限
默认值
u+w,go-w,a+rX(对于Debug和Release)
以下代码片段第 8 行中的点是什么意思,来自/etc/profileMac OS X Mavericks 终端的源代码。
1 # System-wide .profile for sh(1)
2
3 if [ -x /usr/libexec/path_helper ]; then
4 eval `/usr/libexec/path_helper -s`
5 fi
6
7 if [ "${BASH-no}" != "no" ]; then
8 [ -r /etc/bashrc ] && . /etc/bashrc
9 fi
Run Code Online (Sandbox Code Playgroud) 我有一个Android 2.2目标库项目,它MyLibraryGooglePlusSocialPlugin.java有一个import com.google.android.gms.plus.GooglePlusUtil;未能编译(GooglePlusUtil cannot be resolved),而其他人没关系:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.common.Scopes;
import com.google.android.gms.plus.PlusClient;
import com.google.android.gms.plus.PlusClient.OnPeopleLoadedListener;
import com.google.android.gms.plus.PlusClient.OnPersonLoadedListener;
import com.google.android.gms.plus.PlusShare;
import com.google.android.gms.plus.model.people.Person;
import com.google.android.gms.plus.model.people.PersonBuffer;
Run Code Online (Sandbox Code Playgroud)
我今天通过Android SDK管理器更新了相关的Google服务,并设置了构建路径和依赖关系.
objective-c ×3
compilation ×2
swift ×2
xcode ×2
android ×1
bash ×1
c ×1
inheritance ×1
init ×1
ios ×1
nsnull ×1
nsstring ×1
null ×1
optimization ×1
xcode5 ×1