问题:

切入追逐我已经重新创建了我的问题,因为它是相当自我解释的。

这符合,没有错误:

switch (n) {
    case 1:
        NSLog(@"");
        NSString *aStr;
        break;
    default:
        break;
    }

这编译错误 ,它只缺少NSLog():

switch (n) {
    case 1:
        NSString *aStr;
        break;
    default:
        break;
    }

它在编译时出现错误“NSString’之前的预期表达式

我在这里错过了什么吗?

Cut to the chase I have recreated my problem as it is fairly self explanatory.this complies without error:this compiles with error and it’s only missing the NSLog():it throws an error at compile ” Expected expression before ‘NSString’ “Am I missing something here?

问题:

在Cocoa中,何时应该使用NSAssert,NSException,NSError?

这就是我一直在想的:

NSAssert – 在创建任何用于程序员自身利益的客户端程序时,可以仔细检查规则,约定,假设或前置条件和后置条件?

NSException – 为了使用该库的其他程序员的利益创建第三方库,以便他们立即知道输入何时无效?

NSError – 当与外部系统连接以获取不保证给我结果的文件,数据库或Web服务等数据时?

In Cocoa, when should I use NSAssert, NSException, NSError?Here’s what I’ve been thinking:NSAssert – When creating any client program used for the programmers own benefit to double check rules, conventions, assumptions, or pre-conditions and post-conditions?NSException – When creating a third-party library for the benefit of other programmers that use the library, so that they immediately know when an input is invalid?NSError – When interfacing with an external system to get data like a file, database, or web service that isn’t guaranteed to give me a result?

问题:

我在Objective-C中编写应用程序,我收到此错误:

MyApp(2121,0xb0185000)malloc:***对象0x1068310错误:双重免费
***在malloc_error_break中设置断点以进行调试

当我发布一个NSAutoreleasePool并且我无法弄清楚我要发布两次的对象时,就会发生这种情况。

我该如何设置他的断点?

有没有办法知道这个“对象0x1068310”是什么?

I’m programming an application in Objective-C and I’m getting this error:MyApp(2121,0xb0185000) malloc: *** error for object 0x1068310: double free*** set a breakpoint in malloc_error_break to debugIt is happening when I release an NSAutoreleasePool and I can’t figure out what object I’m releasing twice.How do I set his breakpoint?Is there a way to know what is this “object 0x1068310”?

问题:

这个问题在这里已有答案:

2016-09-17 15:16:04.386085 appDemo[2371:94976] [] __nwlog_err_simulate_crash simulate crash already simulated **"nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"**
2016-09-17 15:16:04.386676 appDemo[2371:94976] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
        [x86_64] libnetcore-856.1.8
    0   libsystem_network.dylib             0x0000000112dc780e __nw_create_backtrace_string + 123
    1   libnetwork.dylib                    0x0000000113bfa194 nw_socket_add_input_handler + 3002
    2   libnetwork.dylib                    0x0000000113bd7db8 nw_endpoint_flow_attach_protocols + 3768
    3   libnetwork.dylib                    0x0000000113bd6dd5 nw_endpoint_flow_setup_socket + 563
    4   libnetwork.dylib                    0x0000000113bd5b34 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612
    5   libnetwork.dylib                    0x0000000113bf0d11 nw_endpoint_handler_path_change + 1261
    6   libnetwork.dylib                    0x0000000113bf0740 nw_endpoint_handler_start + 570
    7   libdispatch.dylib                   0x0000000112b44980 _dispatch_call_block_and_release + 12
    8   libdispatch.dylib                   0x0000000112b6e
2016-09-17 15:16:04.387153 appDemo[2371:94976] [] nw_endpoint_flow_attach_protocols [2 192.168.0.100:80 in_progress socket-flow (satisfied)] Attached flow protocol
2016-09-17 15:16:04.387679 appDemo[2371:94976] [] nw_connection_endpoint_report [2 192.168.0.100:80 in_progress socket-flow (satisfied)] reported event flow:start_connect

我正在使用带有ios 10 xcode 8版本。 现在,我正在使用API​​。 如果,我在Xcode 7它的工作正常,但是当我在xcode 8使用相同的API时出现错误消息无法解析。

This question already has an answer here:Hide strange unwanted Xcode logs 12 answersI’m using xcode 8 version with ios 10 .Now, I’m working an API.If, I use the API in Xcode 7 its works fine but when same API I used in xcode 8 error message appears Unable to parse.

问题:

我有一些代码用于排序日历日期,如下所示:

#if !(TARGET_IPHONE_SIMULATOR)
    NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"HH:mm dd MMM yyyy" options:0
                                                              locale:[NSLocale currentLocale]];
    [fmt setDateFormat:formatString];
#else
    [fmt setDateFormat:@"HH:mm dd MMM yyyy"];
#endif

如果我在模拟器中运行它就可以了。 如果我在设备上运行它,我会得到这个讽刺调试消息。

2012-09-19 22:40:13.972 APPNAME [4923:907] * – [__ NSCFCalendar组件:fromDate:]:日期不能为零

我的意思是,你觉得这个操作应该用零日期来表示什么?

目前已经避免了例外。

这个投诉会报告其中一些错误,然后进一步的违规行为只会默默地做任何随机的事情。 这是此次发生的回溯(由于编译器优化,某些帧可能会丢失):

你必须嘲笑它​​,但我不确定我的dateFormatFromTemplate:代码有什么问题。 任何帮助,将不胜感激。

运行Xcode V 4.5 btw


更新:

回溯:

0 CoreFoundation 0x39ff0e55 + 84
1 APPNAME 0x00040be1 – [MeetingsViewController dateAtBeginningOfDayForDate:] + 140

所以我想我的dateAtBeginningOfDayForDate方法的情况很糟糕。 看起来像这样:

/*
 Break down a given NSDate to its bare components for sorting
 */
- (NSDate *)dateAtBeginningOfDayForDate:(NSDate *)inputDate
{
    // Use the user's current calendar and time zone
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    [calendar setTimeZone:timeZone];

    // Selectively convert the date components (year, month, day) of the input date
    NSDateComponents *dateComps = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:inputDate];

    // Set the time components manually
    [dateComps setHour:0];
    [dateComps setMinute:0];
    [dateComps setSecond:0];

    // Convert back
    NSDate *beginningOfDay = [calendar dateFromComponents:dateComps];
    return beginningOfDay;
}

我使用这种方法将给定的NSDate分解为其核心组件,以便我可以更有效地对它们进行排序。 但是,我的应用程序必须是国际的,这是使用NSLocale日期输出的原因。 从我看来,我需要改变我的dateAtBeginningOfDayForDate以便在国际上工作。

I have some code I use to sort calendar dates that looks like this:If I run it in the simulator all is ok.If I run it on the device I get this sarcastic debug message.2012-09-19 22:40:13.972 APPNAME [4923:907] * -[__NSCFCalendar components:fromDate:]: date cannot be nilI mean really, what do you think that operation is supposed to mean with a nil date?An exception has been avoided for now.A few of these errors are going to be reported with this complaint, then further violations will simply silently do whatever random thing results from the nil.Here is the backtrace where this occurred this time (some frames may be missing due to compiler optimizations):You have to laugh at it but I’m not sure what is wrong with my dateFormatFromTemplate: code.Any help would be appreciated.Running Xcode V 4.5 btwUPDATE:Backtrace:0 CoreFoundation 0x39ff0e55 + 841 APPNAME 0x00040be1 -[MeetingsViewController dateAtBeginningOfDayForDate:] + 140So I guess things are going bad in my dateAtBeginningOfDayForDate method.Which looks like this:I use this method to break down a given NSDate to its’ core components so that I can sort them all more efficiently.However, my app has to be international which is the reason behind using NSLocale to formate the date output.From what it seems I will need to alter my dateAtBeginningOfDayForDate to work internationally as well.