目标C中的块语法(实际上是C,我推测)是众所周知的不协调.将块作为参数传递看起来与将块声明为ivars不同,后者看起来与typedef块不同.
是否有一个完整的块声明语法列表,我可以随时查看以供快速参考?
我有一个企业应用程序,我通过itmsURL 分发:
itms-services://?action=download-manifest&url=itms-services://?action=download-manifest&url=https://$MY_PLIST_URL.plist
Run Code Online (Sandbox Code Playgroud)
在iOS 7上,下载和更新都可以正常工作.但是,在iOS 8上,我收到错误:
LoadExternalDownloadManifestOperation: Ignore manifest download, already have bundleID: com.mycom.MyApp
Run Code Online (Sandbox Code Playgroud)
在我的plist中,我有
<key>bundle-identifier</key>
<string>com.mycom.MyApp</string>
<key>bundle-version</key>
<string>0.2.2</string>
Run Code Online (Sandbox Code Playgroud)
在iOS 8上的应用程序中,我运行的是0.2.1版本
我有一个自定义的UIView子类,它通过一个nib进行初始化.
在-awakeFromNib,我正在创建一个子视图,并试图将其置于超级视图中.
[self setInteralView: [[UIView alloc] init]];
[[self internalView] addConstraint: [NSLayoutConstraint constraintWithItem: [self internalView]
attribute: NSLayoutAttributeCenterX
relatedBy: NSLayoutRelationEqual
toItem: self
attribute: NSLayoutAttributeCenterX
multiplier: 1
constant: 0]];
Run Code Online (Sandbox Code Playgroud)
这会中断,并导致以下输出:
2013-08-11 17:58:29.628 MyApp[32414:a0b] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0xc1dcc80 UIView:0xc132a40.centerX == MyView:0xc1315a0.centerX>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break …Run Code Online (Sandbox Code Playgroud) objective-c ios autolayout uiview-hierarchy nslayoutconstraint
我正在使用此代码:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle: @"Title"];
[notification setSubtitle: @"Subtitle"];
[notification setInformativeText: @"Informative Text"];
[notification setHasActionButton: YES];
[notification setActionButtonTitle: @"Action Button"];
[notification setOtherButtonTitle: @"Other Button"];
[notification setSoundName: NSUserNotificationDefaultSoundName];
[notification setDeliveryDate: [NSDate dateWithTimeIntervalSinceNow: 10]];
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification: notification];
}
Run Code Online (Sandbox Code Playgroud)
我得到了,但没有失败,

没有操作按钮或其他按钮.
这会导致任何类型的保留周期吗?使用安全吗?
__block void (^myBlock)(int) = [^void (int i)
{
if (i == 0)
return;
NSLog(@"%d", i);
myBlock(i - 1);
} copy];
myBlock(10);
myBlock = nil;
Run Code Online (Sandbox Code Playgroud) recursion objective-c objective-c-blocks automatic-ref-counting
我试图通过UI Automation自动化用户的路径.理想情况下,a中的用户位置MKMapView将根据我在自动化脚本中表达的路标列表进行更新:
var target = UIATarget.localTarget();
var waypoints = [
{location: {latitude: 37.33170, longitude: -122.03020}, options: {course: 180}},
{location: {latitude: 37.33170, longitude: -122.03022}, options: {course: 180}},
{location: {latitude: 37.33170, longitude: -122.03025}, options: {course: 180}},
{location: {latitude: 37.33170, longitude: -122.03027}, options: {course: 180}},
{location: {latitude: 37.33170, longitude: -122.03030}, options: {course: 180}},
{location: {latitude: 37.33170, longitude: -122.03032}, options: {course: 180}},
{location: {latitude: 37.33170, longitude: -122.03035}, options: {course: 180}},
{location: {latitude: 37.33170, longitude: -122.03037}, options: {course: 180}},
{location: {latitude: 37.33170, longitude: …Run Code Online (Sandbox Code Playgroud) 所以,我试图传递一个块作为NSAlert contextInfo参数.
[myAlert beginSheetModalForWindow: theWindow
modalDelegate: myAlert
didEndSelector: @selector(alertDidEnd:returnCode:contextInfo:)
contextInfo: (void *) aBlock];
Run Code Online (Sandbox Code Playgroud)
然后把它拿回到另一端:
void (^responseBlock)() = (__bridge_transfer void (^)()) contextInfo;
Run Code Online (Sandbox Code Playgroud)
哪种方式有效.在我调用beginSheetModalForWindow:...aBlock 之前0x00007fff610e1ec0,在response(alertDidEnd:...)中,contextInfo处于0x00007fff610e1ec0.
但是,当我尝试调用块时:
responseBlock();
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
错误:调用对象类型'__block_literal_generic*'不是函数或函数指针
错误:1错误解析表达式
void *为了简单的转移,如何正确地将一个块转换为s?
编辑:
完整的尝试代码,使用答案中建议的强制转换方法.我现在在responseBlock();通话时收到EXC_BAD_ACCESS错误.
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
void (^responseBlock)() = (__bridge typeof(responseBlock)) contextInfo;
switch (returnCode)
{
case NSCancelButton:
{
break;
}
case NSOKButton:
{
responseBlock();
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
其他注意事项:
使用时__bridge,内存地址responseBlock和 …
我精通典型的范例:
//.h
extern const int myInt;
//.c, .m, .cpp, what have you
const int myInt = 55;
Run Code Online (Sandbox Code Playgroud)
但是必须有一种方法可以将其放入.h文件中,以便与库或其他无法访问实现文件的实例一起使用.
例如,我正在尝试向Xcode项目中NSString的.h文件添加一个常量,如下所示:
static NSString *const myString = @"my_string";
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用时myString,我得到了错误
Initializer元素不是编译时常量
on myString,表示未正确实例化.如何在C++或Objecitve-C头文件中声明编译时常量?
c++ constants objective-c header-files compile-time-constant
鉴于上课Obj,
class Obj: NSObject {
var x = "x"
}
Run Code Online (Sandbox Code Playgroud)
和它的子类,Obj1你如何更改默认值var x?
简单地设置一个新值将是最有意义的,但似乎错误...
class Obj1: Obj {
var x = "y"
}
Run Code Online (Sandbox Code Playgroud)
❗️无法覆盖存储的属性'x'
overriding instance-variables default-value subclassing swift
我已经将纯Swift 2二进制文件上传到iTunes Connect,希望通过Test Flight进行分发.
根据iTunes Connect本身,这应该是可能的:

不幸的是,我的二进制文件遇到"无效二进制"错误:

显然,我已经尝试了几次.什么也没有工作:
Embedded Content Contains Swift Code为YESEmbedded Content Contains Swift Code为NOEnable Bitcode为YES (找不到我尝试过的原因)Enable Bitcode为NO我通过电子邮件收到的错误是:

这似乎暗示从iTunes Connect获取的第一个屏幕截图是错误的.我疯了吗?(有些人认为我们都有.)
更新:似乎有些人可以上传他们的iOS 9测试版.在再次运行所有这些尝试后,我不是那些人之一.
更新:这只发生在我的某个应用中.两者之间唯一的来源或依赖关系是失败的应用程序使用Parse SDK Cocoapod.
objective-c ×5
ios ×4
xcode ×2
autolayout ×1
c++ ×1
casting ×1
cocoa ×1
constants ×1
header-files ×1
ios8 ×1
iphone ×1
javascript ×1
mapkit ×1
overriding ×1
recursion ×1
subclassing ×1
swift ×1
swift2 ×1
syntax ×1