感谢Yuji回答了我的另一个问题,并向我指了一篇关于Objective-C中动态ivars的文章.
然而,正如我在解释的其他问题的sizeof运营商现在的行为不一致.简而言之,sizeof不会考虑来自类.m文件外部的动态ivars,但会.m在@synthesize创建动态ivars 的声明之后将其考虑在文件中.
所以我的问题是,这是否打破了Objective-C是C的严格超集的想法?
这对于一致的命名方法很有用,例如让我们看看UITableViewDataSource协议中的一些方法名称:
numberOfSectionsInTableView:
tableView:heightForHeaderInSection:
tableView:viewForHeaderInSection:
tableView:heightForFooterInSection:
tableView:viewForFooterInSection:
tableView:numberOfRowsInSection:
tableView:cellForRowAtIndexPath:
sectionIndexTitlesForTableView:
Run Code Online (Sandbox Code Playgroud)
注意第一个和最后一个是奇数 - 它们仍然将a UITableView*作为第一个参数,但因为它是唯一的参数,所以命名约定的一致性被破坏.如果它们可以这样命名会更好:
tableView:numberOfSections
tableView:sectionIndexTitles
Run Code Online (Sandbox Code Playgroud)
是否可以定义这样或类似的方法?我试过这些:
- (NSUInteger)specialView:(SpecialView*)specialView numberOfThingies;
- (NSUInteger)specialView:(SpecialView*)specialView numberOfThingies:(void)unused;
Run Code Online (Sandbox Code Playgroud)
第一个是理想的,但会导致头文件出错.第二个是不理想的(如果最后没有冒号会更好)但是它在标题中被接受,我无法弄清楚如何调用它.我尝试过各种变化:
[anObject specialView:aSpecialView numberOfThingies];
[anObject specialView:aSpecialView numberOfThingies:];
[anObject specialView:aSpecialView numberOfThingies:void];
[anObject specialView:aSpecialView numberOfThingies:(void)0];
Run Code Online (Sandbox Code Playgroud)
有办法做我想做的事吗?是否还有其他任何合理的命名约定,以保持这些方法的一致性?
在从命令行构建Xcode项目时,有很多关于控制放置'build'目录的问题/答案,但是有没有办法获得Xcode使用的路径?
我知道它将文件放在~/Library/Developer/Xcode/DerivedData/APPNAME-xxx/Build/xxx是一些随机字符串的位置.我希望能够到该目录在命令行中获得,这样我可以存档我.app和.dSYM文件,并重新签订和我的包.app使用xcrun PackageApplication,这是我目前用它来创建一个在空中安装版本直接形成积-server(哈德森).
我有一个界面:
public interface Profile
{
string Name { get; }
string Alias { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
实现的所有对象Profile都有 aName和 an Alias,但有些限制Alias使其始终与Name. 应用此限制的人可以这样实现Alias:
string Profile.Alias
{
get
{
return ((Profile)this).Name;
}
set { }
}
Run Code Online (Sandbox Code Playgroud)
由于this在显式接口实现的上下文中只能是类型,Profile并且我们知道它是通过Profile接口而不是包含类或它实现的任何其他接口访问的,为什么需要强制转换?
使用return this.Name;了此错误,吸气实施效果:
Type `ConcreteProfile' does not contain a definition for `Name' and no extension method `Name' of type `ConcreteProfile' could be found (are you missing a …Run Code Online (Sandbox Code Playgroud)