{"id":809,"date":"2023-04-02T04:44:53","date_gmt":"2023-04-02T04:44:53","guid":{"rendered":"http:\/\/robinluo.top\/?p=809"},"modified":"2023-04-02T13:03:50","modified_gmt":"2023-04-02T13:03:50","slug":"objective-c-%e5%a4%9a%e7%ba%bf%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/robinluo.top\/?p=809","title":{"rendered":"objective-c \u591a\u7ebf\u7a0b"},"content":{"rendered":"\n<p>NSThread \u4e3aobjective-c \u7684\u591a\u7ebf\u7a0b\u5bf9\u8c61<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n#import \"Saler.h\"\n\n@implementation Saler\n\n-(Saler*) init{\n    self = &#91;super init];\n    NSLog(@\"init saler\");\n    self.ticket = &#91;NSNumber numberWithInt:20];\n    return self;\n}\n\n-(void) startSale{\n    NSThread *thread = &#91;NSThread new];\n    self->thread = thread;\n    &#91;thread initWithTarget:self selector:@selector(run) object:nil];\n\/\/\u8be5\u8bbf\u95ee\u6307\u660e\u8c03\u7528self.run \u65b9\u6cd5\u4f5c\u4e3a\u7ebf\u7a0b\u8fd0\u884c\u4ee3\u7801 \n    &#91;thread start];\n}\n\n-(void) run{\n    NSLog(@\"running\");\n}\n\n@end<\/code><\/pre>\n\n\n\n<p>main \u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#import &lt;Foundation\/Foundation.h>\n#import \"Saler.h\"\n\nint main(int argc, const char * argv&#91;]) {\n    @autoreleasepool {\n        Saler* saler1 = &#91;Saler new];\n        Saler* saler2 = &#91;Saler new];\n        &#91;saler1 startSale];\n        &#91;saler2 startSale];\n        NSLog(@\"starting\");\n    }\n    \n   \n    \n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p>console output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>2023-04-02 20:58:33.568419+0800 CMD&#91;2079:186178] init saler\n2023-04-02 20:58:33.568662+0800 CMD&#91;2079:186178] init saler\n2023-04-02 20:58:33.569828+0800 CMD&#91;2079:186178] starting\n2023-04-02 20:58:33.570763+0800 CMD&#91;2079:186233] running\n2023-04-02 20:58:33.570776+0800 CMD&#91;2079:186234] running\nProgram ended with exit code: 0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>NSThread \u4e3aobjective-c \u7684\u591a\u7ebf\u7a0b\u5bf9\u8c61 main \u51fd\u6570 console output<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[132],"tags":[],"_links":{"self":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/809"}],"collection":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=809"}],"version-history":[{"count":2,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/809\/revisions"}],"predecessor-version":[{"id":829,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/809\/revisions\/829"}],"wp:attachment":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}