在Objective-C或任何其他适用的语言?
我想我要问的是,是__weak和const在分类方面一样吗?我可以互换的条款类型和寿命预选赛时,我说的是__weak,const等?
当我尝试使用ARC使用以下SQLite代码执行此操作时,我收到该错误:
NSMutableArray *rows = [[NSMutableArray alloc] init];
sqlite3_exec(database, "select distinct category from billy", callback, rows, NULL);
Run Code Online (Sandbox Code Playgroud)
有人知道怎么修这个东西吗?
使用ARC for iOS时,以下是否有任何区别?
@property (strong, nonatomic) NSObject *someProperty;
...
@synthesize someProperty;
//and then in the init method, either:
self.someProperty = aProperty;
//or
someProperty = aProperty;
Run Code Online (Sandbox Code Playgroud)
我知道没有ARC,self.someProperty实际上是调用合成的setter方法,它向retain对象发送一条消息.但是现在使用ARC,如果我使用点符号设置这样的属性是否重要?
更一般地说,ARC真的意味着我根本不必担心引用计数吗?或者在某些情况下,我编写代码的方式可能会导致ARC出错?
嗨,我在ARC下有一个令人讨厌的内存管理问题,无法弄清楚如何解决它.问题就像这样,我有这些对象:
ObjectManager - 对核心数据执行fetchRequests并获取一个或多个NSManagedObjects的单例
UIViewControllerA - 一个视图控制器,其中有一个按钮"PassManagedObject"和一个声明如下的属性:
@property (strong, nonatomic) ManagedObject *objectForToday;
Run Code Online (Sandbox Code Playgroud)
在UIViewControllerA上的viewDidLoad中,我调用了方法refreshDailyObject,它执行此操作:
self.objectForToday = nil;
self.objectForToday = [[ObjectManager sharedManager] getDailyObject];
Run Code Online (Sandbox Code Playgroud)
如果我挖掘的PassManagedObject按钮I 创建UIViewControllerB,通过所述objectForToday它和显示它,见下文
- (IBAction)passManagedObjectTapped:(id)sender {
UIViewControllerB *viewController = [[UIViewControllerB alloc] initWithNibName:@"UIViewControllerB"];
viewController.object = self.objectForToday;
[self.navigationController pushViewController:viewController animated:NO];
}
Run Code Online (Sandbox Code Playgroud)
UIViewControllerB有一个声明如下的属性:
@property (strong, nonatomic) ManagedObject *object;
Run Code Online (Sandbox Code Playgroud)
和一个按钮" 后退 ",它执行此操作:
- (IBAction)backAction:(id)sender {
self.object = nil;
[self.navigationController popViewControllerAnimated:NO];
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是这个.如果我点击不断passManagedObjectTapped然后backAction,并再次passManagedObjectTapped又一次backAction,然后再passManagedObjectTapped和自动化这个我得到最终收到内存警告1,然后崩溃. …
memory-management core-data objective-c ios automatic-ref-counting
我正在处理的应用程序的一部分涉及UIPageViewController,其中每个页面显示存储在Core Data中的"条目".除了别的以外,条目还包括一些被压缩并存储为NSData的图像.因此,要加载这些图像并将它们显示在页面上,我正在使用imageWithData,即
photo.image = [UIImage imageWithData:entry.photo];
Run Code Online (Sandbox Code Playgroud)
问题是imageWithData不是特别快,因此翻页不像我想的那样响应.解决这种情况的最佳尝试是将我的UIPageViewController显示的一些视图控制器预加载到一个数组中.(不确定这是否是最好的事情,但你有它)
所以,为了澄清,我有一个导航控制器,它包含viewControllerA,然后链接到viewControllerB - 它显示UIPageView和entryControllers(每页上有一个entryController).问题是,当我使用导航栏从viewControllerB返回到viewControllerA时,我希望viewControllerB的entryControllers数组从内存中释放.但是,ARC似乎并没有这样做.因此,在viewControllerA和viewControllerB之间来回几次,每次翻几页,我开始得到内存警告 - 这最终清除了当前的entryControllers数组,并且失败了拥有该数组的目的,因为每次收到内存警告时,都必须重新加载条目.
简而言之,当我通过导航控制器返回viewControllerA时,ARC没有清除我为viewControllerB分配的任何内存.我不喜欢那样.如果有人可以提出这种情况发生的原因,或者让我知道如果我以错误的方式处理这一切,那将非常感激.我只是想加快从一个页面到下一个页面的过渡!
谢谢一堆.
我有一个非常具体的问题,我正在使用一个采用varius状态的DAO(数据访问对象),这些状态被传递到init方法然后被使用.
现在我遇到的问题是我似乎无法将具体状态传递给init方法,我总是得到一个
使用ARC不允许将Objective-c指针隐式转换为__autoreleasing id
代码:
-(DAOObject *)makeSpecificDataAccessObject{
SQLiteState* localstate = [[SQLiteState alloc] initWithTableName:@"TableName"];
DAOObject* specificDAO = [[DAOObject alloc] initWithLocalState:localstate]; //where error happens
return specificDAO;
}
@interface DAOObject : NSObject <SettingsListenerProtocol>
-(id)initWithLocalState:(id<StateProtocol> *)LocalState;
@end
@interface SQLiteState : NSObject <StateProtocol>
-(id)initWithTableName:(NSString *)tableName;
@end
Run Code Online (Sandbox Code Playgroud) compiler-errors objective-c implicit-conversion automatic-ref-counting
我正在寻找的是一个以顺时针方式显示图像的视图.当进度为25%时,应显示前90度,当其100%时,应绘制全部360度.
它非常接近使用canvas.drawArc(),但此方法仅适用于Paint对象,而不适用于位图.
其他答案也只适用于全彩色: 如何在Android中制作圆形自定义进度条
我发现这是一个非常难的问题,我希望有人有解决方案.
我很想在我的项目中加入arc.我正在尝试理解__bridge及其小朋友,以便在从容器中添加和删除它时可以正确地投射我的CGImageRef.
我在我的一条线上得到了"存储对象的潜在泄漏......".这是我的代码的基本循环:
CGImageRef renderedRef = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext());
[_array addObject: (__bridge_transfer id)renderedRef];//_array is an iVar
Run Code Online (Sandbox Code Playgroud)
然后在某个地方,我这样做:
CGImageRef iRef = (__bridge_retained CGImageRef)array[0];
//then I do something fancy with iRef
//at the end of the method, I get "Potential leak of an object stored…"
//I have no idea what to do
//I've tried CGImageRelease(iRef); but it still doesn't change the warning.
Run Code Online (Sandbox Code Playgroud)
有人可以对此有所了解吗?另外,我尝试过只使用__bridge,但这没有什么区别.
编辑1:
我扩展了分析仪结果并跟踪发生的情况.这是因为我在这样的方法中使用iRef:[self doSomethingFancy:iRef]; 在那种方法中,iRef被保留但未被释放.所以这修复了警告,但我仍然有点困惑.
关于何时使用各种__bridge演员,我不是很清楚.在ARC下,以下是否增加了引用计数?
CGImageRef iRef = (__bridge CGImageRef)array[0];
Run Code Online (Sandbox Code Playgroud)
此外,在某些时候,如果我告诉我的_array iVar删除AllObjects,那会减少他们的引用计数吗?
objective-c ios cgimageref automatic-ref-counting toll-free-bridging
我正在研究引用计数如何在Swift中工作.在下面的代码片段中,我实例化了一个全新的Person对象,并检查它是否被唯一引用.我认为它是唯一引用的,因为它只保留在"人"实例上.但是,isUniquelyReferencedNonObjC函数返回false.
谁能解释为什么会这样?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var person = Person()
// this will output not unique
if isUniquelyReferencedNonObjC(&person) {
println("unique")
} else {
println("not unique")
}
return true
}
Run Code Online (Sandbox Code Playgroud)
人员类:
class Person: NSObject {
}
Run Code Online (Sandbox Code Playgroud)
编辑有趣的是,当我不使Person成为NSObject的子类时,isUniquelyReferencedNonObjC将按预期返回true.但是,我仍然不明白为什么子类化NSObjct会在这里产生影响.
提前致谢.
在ARC(自动引用计数)工作时在Objective-C或Swift中?在编译阶段还是在运行时阶段?那为什么重要呢?
ios ×6
objective-c ×6
swift ×2
android ×1
bitmap ×1
cgimageref ×1
clip ×1
cocoa-touch ×1
core-data ×1
iphone ×1
progress ×1
sqlite ×1