小编Pat*_*ini的帖子

块声明语法列表

目标C中的块语法(实际上是C,我推测)是众所周知的不协调.将块作为参数传递看起来与将块声明为ivars不同,后者看起来与typedef块不同.

是否有一个完整的块声明语法列表,我可以随时查看以供快速参考?

syntax objective-c objective-c-blocks

276
推荐指数
6
解决办法
8万
查看次数

iOS 8上的企业应用更新分发

我有一个企业应用程序,我通过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版本

xcode ios enterprise-distribution ios8

110
推荐指数
6
解决办法
5万
查看次数

在autolayout中居中子视图的X会抛出"没有为约束做好准备"

我有一个自定义的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

81
推荐指数
5
解决办法
5万
查看次数

NSUserNotification未显示操作按钮

我正在使用此代码:

- (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)

我得到了,但没有失败,

在此输入图像描述

没有操作按钮或其他按钮.

cocoa osx-mountain-lion nsusernotification

40
推荐指数
3
解决办法
1万
查看次数

递归块保留周期

这会导致任何类型的保留周期吗?使用安全吗?

__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

20
推荐指数
2
解决办法
4124
查看次数

UIATarget.setLocationWithOptions课程不适用

我试图通过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)

javascript core-location ui-automation mapkit ios

15
推荐指数
1
解决办法
812
查看次数

如何在空白之间施放区块*

所以,我试图传递一个块作为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和 …

casting objective-c void-pointers objective-c-blocks

14
推荐指数
1
解决办法
3506
查看次数

在头文件中声明并初始化常量

我精通典型的范例:

//.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

14
推荐指数
1
解决办法
2万
查看次数

覆盖实例var的默认值

鉴于上课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

11
推荐指数
3
解决办法
5242
查看次数

"无效二进制"iTunes Connect(Swift 2)

我已经将纯Swift 2二进制文件上传到iTunes Connect,希望通过Test Flight进行分发.

根据iTunes Connect本身,这应该是可能的:

在此输入图像描述

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

在此输入图像描述

显然,我已经尝试了几次.什么也没有工作:

我通过电子邮件收到的错误是:

在此输入图像描述

这似乎暗示从iTunes Connect获取的第一个屏幕截图是错误的.我疯了吗?(有些人认为我们都有.)

更新:似乎有些人可以上传他们的iOS 9测试版.在再次运行所有这些尝试后,我不是那些人之一.

更新:这只发生在我的某个应用中.两者之间唯一的来源或依赖关系是失败的应用程序使用Parse SDK Cocoapod.

iphone xcode itunesconnect ios swift2

9
推荐指数
1
解决办法
711
查看次数