小编Pat*_*pel的帖子

对于CF类型,带有__attribute __((NSObject))的强大@property不会保留

更新:此问题已在Xcode 4.6中修复!

此技术现在再次按预期工作.但是,在您的代码中使用之前,请务必阅读Rob Napier优秀答案顶部的注释.

原始邮政

(ARC,Xcode 4.3.1,iOS 5.1)

我有一个CF类型(CGImage)的强大属性,我希望由ARC自动管理__attribute__((NSObject))(如在合成的setter中保留和释放,并且它在dealloc中没有),但是它不起作用:分配属性时不保留对象.

重现的最小例子:

@interface TestClass : NSObject
@property (nonatomic, strong) __attribute__((NSObject)) CFStringRef str;
@end

// ...In some function
CFStringRef str = (__bridge CFStringRef)[NSString stringWithFormat:@"%g", 2.5];
NSLog(@"%ld", CFGetRetainCount(str));
TestClass *obj = [[TestClass alloc] init];
obj.str = str;
NSLog(@"%ld", CFGetRetainCount(str));
Run Code Online (Sandbox Code Playgroud)

其中两次打印"1".

现在奇怪的是(虽然我不确定)我认为它在我更新到iOS 5.1和Xcode 4.3.1(来自iOS 5和Xcode 4.2)之前正常工作,并且它从gdb切换到lldb.未升级(或知道如何更改编译器)的人可能会确认吗?

objective-c core-foundation ios automatic-ref-counting

21
推荐指数
1
解决办法
4766
查看次数

保留核心基金会财产

(Xcode 4.2,iOS 5,ARC)

我有一些Core Foundation(/ Graphics)对象的属性应该取得对象的所有权.现在在这些Apple文档中我发现了这个:

在OS X v10.6及更高版本中,您可以使用__attribute__关键字指定应将Core Foundation属性视为用于内存管理的Objective-C对象: @property(retain) __attribute__((NSObject)) CFDictionaryRef myDictionary;

不幸的是我找不到任何详细说明.我正在使用这个:

@property (nonatomic, strong) __attribute__((NSObject)) CGImageRef loupeImage;

它看起来像我期望的那样工作.它保留了设置属性的对象,并在将属性设置为nil时将其释放.

现在我的问题是,我还需要在dealloc中将这些属性显式设置为nil吗?

objective-c core-foundation ios automatic-ref-counting

12
推荐指数
1
解决办法
2607
查看次数

在.xib中没有UITableView的内容属性

(XCode 4.2,iOS 5)

为了重用tableview(带有导航栏和编辑/添加按钮),我创建了一个UITableViewController自己的子类.xib.但是,当我UITableView在我.xib的主视图中添加一个内容属性(我想设置为动态原型)时,它不会显示出来.它只显示示例内容(California: Brea, Burlingame, ...).当我UITableView在我的主故事板中添加一个内容属性确实显示.

有什么问题?

cocoa-touch interface-builder uitableview

7
推荐指数
1
解决办法
1187
查看次数

使用带有rootViewController的第二个UIWindow时,黑屏的界面旋转

(iOS 7.0.3,Xcode 5.0.1)

我的应用程序中有第二个UIWindow,用于在状态栏上方显示自定义放大镜.但是,一旦我设置了这个窗口的rootViewController(用于界面旋转和其他一些东西),主窗口在界面旋转动画期间变黑.

要重现:创建单视图iOS应用程序并将以下内容添加到主UIViewController中.

// To @interface:
@property (nonatomic, strong) UIWindow *secondWindow;
// In viewDidLoad:
self.secondWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.secondWindow.rootViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
self.secondWindow.hidden = NO;
Run Code Online (Sandbox Code Playgroud)

任何帮助赞赏.

objective-c uiviewcontroller uiwindow ios

6
推荐指数
1
解决办法
1538
查看次数

为arm64 iOS构建C库(GMP)

我正在尝试为arm64构建一个用于iOS的C库(GMP 6.0.0).我正在使用下面的调用运行configure脚本(使用xcrun --find找到编译器).

./configure \
CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" \
CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E" \
CPPFLAGS="-target arm64-apple-darwin -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/ -miphoneos-version-min=7.0" \
--host=aarch64-apple-darwin
Run Code Online (Sandbox Code Playgroud)

然而,这在以下行失败("长期可靠性测试1"):

checking compiler /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -O2 -pedantic  -target arm64-apple-darwin -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/ -miphoneos-version-min=7.0... no, long long reliability test 1
configure: error: could not find a working compiler, see config.log for details
Run Code Online (Sandbox Code Playgroud)

完整的config.log 在这里可用.它显示了长期可靠性测试编译的多个警告和错误,包括以下内容:

conftest.c:9:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
f(){static const struct{t1 n;t1 src[9];t1 want[9];}d[]={{1,{0},{1}},};t1 got[9];int i;
^
conftest.c:10:44: error: implicit declaration of function 'h' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
for(i=0;i<1;i++){if(e(got,got,9,d[i].n)==0)h();g(i,d[i].src,d[i].n,got,d[i].want,9);if(d[i].n)h();}} …
Run Code Online (Sandbox Code Playgroud)

clang gmp ios arm64

6
推荐指数
1
解决办法
3334
查看次数

如何到达CGPath进行命中测试?

我有一个开放的CGPath/UIBezierPath,如果用户触摸它,我想检测它,即一个点是否在距路径一定距离内.路径是开放的(即线/曲线,而不是形状).它可以包含直线和弯曲元素.如何到达测试路径的距离?

core-graphics objective-c cgpath

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