说你做
MyLock *lock = [[MyLock new] autorelease];
@synchronized(lock) {
    NSLog(@"Hello World");
//some very long process
}
Run Code Online (Sandbox Code Playgroud)
在主线程中.这是否意味着//直到某个很长的进程完成,主线程被锁定了?如果其他一些线程调用
    //Update on the main thread
    dispatch_sync(dispatch_get_main_queue(), ^{
        //Do some updates
    });
Run Code Online (Sandbox Code Playgroud)
永远不会调用一些更新?我对么?
我设置了这个NSAssert
NSAssert(isStillLoadingArgument== [[self class] stillLoading],@"Hmm.... we think isStill Loading is false or true and yet stillLoading is true");;
Run Code Online (Sandbox Code Playgroud)
这是我问这个问题的截图:

然后当断言失败时,代码在这里中断:

这是非常烦人的,因为我想在代码中看到断言中断我设置了断言.那么,我该怎么做呢.
Ben答案遗憾的是没有解决问题:

我认为因为NSManagedObject由managedObject上下文管理,所以指针应该是弱的.
然而,在我的情况下,它往往会回到0.
    for (CategoryNearby * CN in sorted) {
        //[arrayOfItems addObject:[NSString stringWithFormat:@"%@ - %d",CN.name,[CN.order intValue]]];
        NearbyShortcutTVC * tvc=[[NearbyShortcutTVC alloc]init];
        tvc.categoryNearby =CN;
//        tvc.titleString=[NSString stringWithFormat:@"%@",CN.name];
//        tvc.displayed=CN.displayed;
        [arrayOfItemsLocal addObject:tvc];
        //CN
        PO(tvc);
        PO(tvc.categoryNearby);
        while (false);
    }
    self.arrayOfItems = arrayOfItemsLocal;
    PO(self.categoriesNearbyInArrayOfItems);
    [self.tableViewa reloadData];
Run Code Online (Sandbox Code Playgroud)
...
然而在某个地方:
tvc.categoryNearby 变成零.
我不知道它是如何,何时或何地变为零.
我该如何调试?或者参考是否应该强大?
这是NearbyShortcutTVC的界面
@interface NearbyShortcutTVC : BGBaseTableViewCell{
}
@property (weak, nonatomic) CategoryNearby * categoryNearby;
@end
Run Code Online (Sandbox Code Playgroud)
为了确保我们正在讨论同一个对象,我打印了NSArray的所有内存地址
它们都是完全相同的对象.但不知何故,对象的categoryNearby属性在某处神奇地设置为null.
 self.categoriesNearbyInArrayOfItems: (
    0x883bfe0,
    0x8b6d420,
    0x8b6f9f0,
    0x8b71de0,
    0xb073f90,
    0xb061a10,
    0xb06a880,
    0x8b74940,
    0x8b77110,
    0x8b794e0,
    0x8b7bf40,
    0x8b7cef0,
    0x8b7f4b0,
    0x8b81a30,
    0x88622d0,
    0x8864e60,
    0xb05c9a0 …Run Code Online (Sandbox Code Playgroud) 说我有NSString*hello = @"hello world";
现在我想要一个有问题的字符串,其中hello world中的地狱是粗体.
网络上有一个功能:
- (NSMutableAttributedString*) word:(NSString*)substringToHighlight{
    NSMutableAttributedString * mutableAttributedString = [[ NSMutableAttributedString alloc]initWithString:self];
    NSUInteger count = 0, length = [mutableAttributedString length];
    NSRange range = NSMakeRange(0, length);
    count = 0,
    length = [mutableAttributedString length];
    range = NSMakeRange(0, length);
    while(range.location != NSNotFound)
    {
        range = [[mutableAttributedString string] rangeOfString:substringToHighlight options:0 range:range];
        if(range.location != NSNotFound) {
            //[mutableAttributedString setTextColor:[UIColor blueColor] range:NSMakeRange(range.location, [word length])];
            range = NSMakeRange(range.location + range.length, length - (range.location + range.length));
            count++;
        }
    }
    return mutableAttributedString;
}
Run Code Online (Sandbox Code Playgroud)
但是,该函数不起作用,因为mutableAttributedString不支持setTextColor
我也试过了 …
NSDate *dateStartAutoComplete = [NSDate date];
[[NSOperationQueue new]addOperationWithBlock:^{
    NSTimeInterval startFetching = [NSDate.date timeIntervalSinceDate:dateStartAutoComplete];
    PO(@(startFetching));
Run Code Online (Sandbox Code Playgroud)
...
结果:
2013-03-15 06:00:12.413 BadgerNew[4120:907] @(tiTotalTime): 0.353954017162323
2013-03-15 06:00:13.476 BadgerNew[4120:8d23] @(startFetching): 0.106734037399292
2013-03-15 06:00:13.502 BadgerNew[4120:8d23] @(finishFetching): 0.1373000144958496
2013-03-15 06:00:13.717 BadgerNew[4120:907] @(tiTotalTime): 0.3521299958229065
2013-03-15 06:00:13.869 BadgerNew[4120:675b] @(startFetching): 0.3048880100250244
2013-03-15 06:00:13.918 BadgerNew[4120:675b] @(finishFetching): 0.3537369966506958
2013-03-15 06:00:14.018 BadgerNew[4120:907] @(tiTotalTime): 0.454010009765625
2013-03-15 06:00:16.317 BadgerNew[4120:8847] @(startFetching): 1.014970004558563
2013-03-15 06:00:16.375 BadgerNew[4120:8847] @(finishFetching): 1.072436988353729
2013-03-15 06:00:16.661 BadgerNew[4120:8d23] @(startFetching): 1.045746028423309
2013-03-15 06:00:16.691 BadgerNew[4120:8d23] @(finishFetching): 1.07514101266861
2013-03-15 06:00:16.721 BadgerNew[4120:907] @(tiTotalTime): 1.419299006462097
2013-03-15 06:00:16.759 BadgerNew[4120:907] @(tiTotalTime): 1.142507016658783 …Run Code Online (Sandbox Code Playgroud) UIImage * imgBtnReloadAllButton = [UIImage resizeableImageWithCapInsets2:UIEdgeInsetsMake(5, 5, 5, 5) withName:@"search_in_this_area"];
[self.btnReloadAllButton setBackgroundImage:imgBtnReloadAllButton forState:UIControlStateNormal];
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateHighlighted]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateNormal]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateSelected]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateReserved]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateApplication]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateDisabled]);
Run Code Online (Sandbox Code Playgroud)
很简单.这就是我所看到的:
2013-03-19 15:22:22.349 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateHighlighted]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.350 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateNormal]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.350 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateSelected]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.350 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateReserved]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.382 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateApplication]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.383 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateDisabled]: <_UIResizableImage: 0xd6b5a80>
(lldb) po imgBtnReloadAllButton
$0 = 0x0d6b5a80 <_UIResizableImage: 0xd6b5a80>
Run Code Online (Sandbox Code Playgroud)
因此看起来所有按钮状态都指向同一图像,即图像0xd6b5a80
然而,当用户点击按钮后,在按下按钮之后但在抬起脏手指之前,按钮看起来不同.
基本上当我按下按钮时,按钮的底角不再是圆形的.
发生了什么?
CFArrayRef refAllPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
NSArray * arPeople = (__bridge_transfer NSArray*)(refAllPeople);
Run Code Online (Sandbox Code Playgroud)
当我分析它说潜在的内存泄漏.
让我试着去理解.refAllPeople有1个参考计数.
然后我做_ bridge _transfer.这将所有权转移给了我.更确切地说,它有arPeople指向它并将保留计数加1.然后保留计数减1,因为_ bridge _transfer等效于(__bridge)后跟CFRelease.
所以,
为什么内存泄漏投诉?
一些Cocoa和Cocoa Touch类声明它们的委托属性assign而不是weak,它强制类的用户nil输出属性dealloc
-(void)dealloc
{
    self.imageScrollView.delegate = nil;
    self.tableView.delegate = nil;
    self.tableView.dataSource = nil;
}
Run Code Online (Sandbox Code Playgroud)
这非常麻烦.
为什么苹果会这样做?
cocoa cocoa-touch delegates automatic-ref-counting declared-property
function dosomething($var1, $var2, $var3='somevalue'){
..
}
Run Code Online (Sandbox Code Playgroud)
关于什么
function dosomething($var3='somevalue',$var1, $var2 )
{
}
Run Code Online (Sandbox Code Playgroud)
我们可以调用doSomething(,1,2);?
这似乎会产生编译错误.
好吧,我有这个页面
domain.com/bla.php?p[]=1&p[]=2&p[]=3&p[]=4
Run Code Online (Sandbox Code Playgroud)
现在,$_GET['p']按预期工作.这是一个阵列
然而,filter_input(INPUT_GET, 'p')产生false.
现在我该怎样得到的数组值p使用filter_input
objective-c ×7
cocoa-touch ×2
php ×2
xcode ×2
xcode4.5 ×2
cocoa ×1
delegates ×1
nsassert ×1
synchronized ×1
xcode4.3 ×1