NSOperation

iOS多线程——你要知道的NSOperation都在这里 你要知道的iOS多线程NSThread、GCD、NSOperation、RunLoop都在这里转载请注明出处 http://www.jianshu.com/p/bf0916ee1492本系列文章主要讲解iOS中多线程的使用,包括:NSThread、GCD、NSOperation以及RunLoop的使用方法详解,本系列文章不涉及基础的线程/进程、同步/异步、阻塞/非阻塞、串行/并行,这些基础概念,有不 阅读详情

转自:http://nshipster.com/nsoperation/


Everyone knows that the secret to making an app snappy and responsive is to offload computation to be done asynchronously in the background. Thus, the modern Objective-C developer has two options: Grand Central Dispatch or NSOperation.

Since GCD has gone pretty mainstream, let's focus on the latter, object-oriented approach.

NSOperation represents a single unit of computation. It's an abstract class that gives subclasses a useful, thread-safe way to model aspects like state, priority, dependencies, and cancellation. Or, if subclassing isn't your cup of tea, there's always NSBlockOperation, a concrete subclass that wraps block in operations.

Examples of tasks that lend themselves well to NSOperation include network requests, image resizing, linguistic processing, or any other repeatable, structured, long-running task that returns processed data.

But simply wrapping computation into an object doesn't do much without a little oversight. That's where NSOperationQueue comes in.

NSOperationQueue regulates the concurrent execution of operations. It acts as a priority queue, such that operations are executed in a roughly First-In-First-Out manner, with higher-priority (NSOperation -queuePriority) ones getting to jump ahead of lower-priority ones. NSOperationQueue also executes operations concurrently, with the option to limit the maximum number to be executed simultaneously (maxConcurrentOperationCount).

To kick off an NSOperation, you can either call -start, or add it to anNSOperationQueue, which will automatically start the operation when it reaches the front of the queue.

Let's go through the different parts of NSOperation, describing how they're used and how to implement them in subclasses:

State

NSOperation encodes a rather elegant state machine to describe the execution of an operation:

isReady → isExecuting → isFinished

In lieu of an explicit state property, state is determined implicitly by KVO notifications on those keypaths. That is, when an operation is ready to be executed, it sends a KVO notification for the isReady keypath, whose corresponding property would then return YES.

Each property must be mutually exclusive from one-another in order to encode a consistent state:

  • isReady: Returns YES to indicate that the operation is ready to execute, or NO if there are still unfinished initialization steps on which it is dependent.
  • isExecuting: Returns YES if the operation is currently working on its task, or NOotherwise.
  • isFinished Returns YES if the operation's task finished execution successfully, or if the operation was cancelled. An NSOperationQueue does not dequeue an operation until isFinished changes to YES, so it is critical to implement this correctly so as to not avoid deadlock.

Cancellation

It may be useful to cancel operations early to prevent needless work from being performed. Reasons for cancellation may include explicit user action, or a failure in a dependent operation.

Similar to execution state, NSOperation communicates changes in cancellation state through KVO on the isCancelled keypath. When an operation responds to the -cancelcommand, it should clean up any internal details and arrive in an appropriate final state as quickly as possible. Specifically, the values for both isCancelled and isFinished need to become YES, and the value of isExecuting to NO.

One thing to definitely watch out for are the spelling peculiarities around the word "cancel". Although spelling varies across dialects, when it comes to NSOperation:

  • cancel: use one L for the method (verb)
  • isCancelled: use two L's for the property (adjective)

Priority

All operations may not be equally important. Setting the queuePriority property will promote or defer an operation in an NSOperationQueue according to the following ranking:

  • NSOperationQueuePriorityVeryHigh
  • NSOperationQueuePriorityHigh
  • NSOperationQueuePriorityNormal
  • NSOperationQueuePriorityLow
  • NSOperationQueuePriorityVeryLow

Additionally, operations may specify a threadPriority value, which is a value between0.0 and 1.0, with 1.0 representing the highest priority. Whereas queuePrioritydetermine the order in which operations are started, threadPriority specifies the allocation of computation once an operation has been started. But as with most threading details, if you don't know what it does, you probably didn't need to know about it anyway.

Dependencies

Depending on the complexity of your application, it may make sense to divide up large tasks into a series of composable sub-tasks. You can do that using NSOperation dependencies.

For example, to describe the process of of downloading and resizing an image from a server, you would probably want to divide up the networking into one operation, and resizing into another (perhaps to reuse the networking operation to download other resources, or reuse the resizing operation for images already on-disk). However, an image can't be resized until its downloaded. Therefore, we say that the the networking operation is a dependency of the resizing operation, and must be finished before the resizing operation can be started. Expressed in code:

[resizingOperation addDependency:networkingOperation];
[operationQueue addOperation:networkingOperation];
[operationQueue addOperation:resizingOperation];

An operation will not be started until all of its dependencies return YES to isFinished. It's important to remember to add all of the operations involved in a dependency graph to the operation queue, lest there be a gap somewhere along the way.

Also, make sure not to accidentally create a dependency cycle, such that A depends on B, and B depends on A, for example. This will create deadlock and sadness.

completionBlock

One useful feature that was added in the blocks renaissance of iOS 4 and Snow Leopard was the completionBlock property.

When an NSOperation finishes, it will execute its completionBlock exactly once. This provides a really nice way to customize the behavior of an operation when used in a model, or view controller. For example, you could set a completion block on a network operation block to do something with the response data from the server once its finished loading.


NSOperation remains an essential tool in the modern Objective-C programmers bag of tricks. Whereas GCD is ideal for in-line asynchronous processing, NSOperation provides a more comprehensive, object-oriented model of computation, which is ideal for encapsulating all of the data around structured, repeatable tasks in an application. Add it to your next project and bring delight not only to your user, but yourself as well!


【iOS】NSOperation NSOperation 是居于objective-c对GCD封装居于面向对象的,线程执行方式;NSOperation配合NSOperationQueue也能实现多线程编程;先将需要执行的操作封装到一个NSOperation对象中然后将NSOperation对象添加到NSOperationQueue中将取出的NSOperation封装的操作放到一条新线程中执行。 阅读详情

相关推荐

DCDC开关节点SW的Layout抉择:打孔换层与EMI共模辐射的权衡

本文深入探讨了DCDC转换器中开关节点SW的Layout设计对EMI共模辐射的影响。通过分析SW节点的EMI辐射机制、打孔换层对输入环路的影响以及铜皮面积与共模辐射的量化关系,提出了工程实践中的权衡策略和优化方法,帮助工程师在设计中平衡EMI性能和电路效率。

weixin_29722783的博客 246

NSOperation的进阶使用和简单探讨

NSOperation类是iOS2.0推出的,通过NSThread实现的,但是效率一般。从OS X10.6和iOS4推出GCD时,又重写了NSOperation和NSOperationQueue,NSOperation和NSOperationQueue分别对应GCD的任务和队列,所以NSOPeration和NSOperationQueue是基于GCD更高一层的封装,而且完全地面向对象。但是比GCD更简单易用、代码可读性也更高。

GJ_ia的博客 533

WINDOWS下SIP拨号的实现

在WIN10上拨打SIP电话  由于我的交换原理实验有一个是关于SIP的抓包的。而之前从未接触过SIP,所以在如何完成一次SIP拨号上遇到了不少问题,查了好多资料都没有完整的或者写的很清楚的,这里就对那些资料做一个总结,给出一个比较完善的解决方案,一来是记录此次实验的收获,而来也可能为其他有同样困惑的人解惑。  废话不多说直接开始。首先是下载一个可以拨打SIP电话的客户终端,这里我选择的是MicroSIP, 下载红圈内的文件,下载好之后直接一路安装即可,没有什么特别注意的地方。  安装好客户端之后,就需要注

weixin_43918519的博客 3807

NSOperation(线程)

简介 NSOperation作用 NSOperation和NSOperationQueue也能实现多线程编程 NSOperation和NSOperationQueue实现多线程的具体步骤 先将需要执行的操作封装到一个NSOperation对象中 然后将NSOperation对象添加到NSOperationQueue中 将取出的NSOperation封装的操作放到一条新线程中执行 NSOpera...

weixin_44729579的博客 2829

告别CPU空转!用STC8的SPI+DMA高效驱动上百颗WS2812B灯珠

本文详细解析了如何利用STC8单片机的SPI+DMA外设高效驱动WS2812B全彩灯珠,解决传统软件延时驱动方式在长灯带应用中的性能瓶颈。通过硬件方案设计、数据格式转换和DMA传输配置,实现高达400Hz的刷新率和低于5%的CPU占用率,适用于大规模灯光项目。

weixin_30847939的博客 397

从AP到ADSP:高通8650 AudioReach中GSL-Passthru-GPR的数据通路剖析

本文深入剖析了高通骁龙8650平台AudioReach架构中,音频数据从应用处理器(AP)到音频数字信号处理器(ADSP)的完整传输路径。重点解析了GSL(Graph Service Layer)如何封装命令,并通过Passthru驱动与GPR(Generic Packet Router)协同工作,实现跨处理器的高效、异步数据交换,揭示了现代手机复杂音频系统背后的核心通信机制。

cherry的博客 536

iOS多线程:『NSOperation、NSOperationQueue』详尽总结

本文用来介绍 iOS 多线程中 NSOperation、NSOperationQueue 的相关知识以及使用方法。通过本文,您将了解到:NSOperation、NSOperationQueue 简介、操作和操作队列、使用步骤和基本使用方法、控制串行/并发执行、NSOperation 操作依赖和优先级、线程间的通信、线程同步和线程安全,以及 NSOperation、NSOperationQueue ...

欢迎来到一度's博客 496

别再死记硬背公式了!用ADS手把手教你仿真一个4GHz镜像抑制混频器(附完整工程文件)

本文详细介绍了使用Keysight ADS软件设计和仿真4GHz镜像抑制混频器的完整流程。从理论分析到实际工程实现,涵盖分支线耦合器设计、二极管建模、噪声系数仿真及性能优化等关键步骤,帮助工程师摆脱公式死记硬背,掌握实用的射频电路设计技能。附完整工程文件,可直接应用于实际项目开发。

weixin_28683391的博客 496

「OC」多线程(三)——NSOperation

在写了知乎日报之前学习了相关的GCD和NSThread的相关内容,然后在知乎日报写完之后,我继续开始OC之中多线程的NSOperation的学习。由于之后肯定是要对和SDWebImage的源码继续相关学习,所以学习NSOperation的相关内容也是给后面做铺垫。NSOperation 是苹果公司对 GCD 的封装,完全面向对象,并比GCD多了一些更简单实用的功能,所以使用起来更加方便易于理解。NSOperation 和NSOperationQueue 分别对应 GCD 的 任务 和 队列。

aa2002aa的博客 1189

YOLOv8的Anchor-Free革新:从中心点预测到动态IoU匹配的全面解析

本文深入解析了YOLOv8采用Anchor-Free(无锚框)设计的核心优势与实现机制。通过摒弃预设锚框,模型直接预测目标中心点与宽高,结合解耦头、动态IoU匹配及Varifocal Loss等创新,显著简化了训练流程并提升了检测精度,尤其在小目标检测和模型泛化能力上表现突出。

weixin_29094301的博客 356

微信小程序 - 最新图片组拖拽排序更换位置功能,类似微信朋友圈九宫格图片的拖动排序效果,微信小程序实现九宫格图片拖拽调换位置,小程序详细实现图像拖曳拖动切换位置排序功能(详细示例代码,一键复制开箱即用

微信小程序,wechat,小程序,图片排序,图像排序,九宫格拖拽排序,拖曳,拖动,拖拽,仿微信朋友圈,朋友圈宫格图片排序,微信朋友圈图片拖动排序效果,实现九宫格图片拖拽,图像拖拽排序组件插件,小程序实现拖拽图片切换图片位置,图片拖动互换位置,图像拖拽切换位置,九宫格图片组合拖动排序,交换九宫格图片的位置,小程序上传图片后,如何实现拖拽排序功能,小程序怎么实现图片拖拽排序,微信小程序图片上传,九宫格拖拽组件,选择图片并拖动_微信小程序图片拖拽,微信小程序长按拖拽排序,图像的拖拽移动,多图拖拽排序功能,实现九宫

✅ 精选推荐文章 4455

多线程之NSOperation

与GCD一样,也是我们日常开发中经常用到的多线程技术。本文将会介绍的基本使用、添加依赖、自定义。

weixin_61196797的博客 529

SPAD IMX479规格_分辨率

当然IMX479具备IMX459几乎全部的数字架构,但也有一个缺点就是贵,这个让头部的主机厂有些犹豫,毕竟大家都在集中火力想把车载LiDAR玩进千元机。如果用一片IMX479是不太可能实现千元内部的,当然国产也在奋起直追,特别在前面的几家SPAD厂商都具备开发IMX479的实力,但相对来说落地可能更是当下所考虑的,IMX479的迭代是基于IMX459,小编已经注意到国内有一两家已经在挑战479的规格了,如果国产SPAD没有大规模量产就直接流片IMX479的规格,可能就有点忽略市场的反馈闭环。

致力于lidar应用开发 2417

NSOperation的使用

一种加入NSOperationQueue: 分为重写main和重写start,重写main不用关心operation对象的释放问题,不要处理任务状态 重写start方法,需要在start方法或者main方法中对finished赋值为yes,operation对象才会释放,并且需要主动调用main方法   另一种直接调用NSOperation,[operation start] 为了防止外...

xiaoyu的博客 2370

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

「iOS」————NSOperation

本文介绍了NSOperation和NSOperationQueue的使用和相关API,同时介绍了如何使用其实现线程间通信和安全

2301_80253909的博客 1776

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

NSOperation 简介

常用子类: NSOperation是一个基类,不应该直接生成NSOperation对象,而是应该用它的子类。 NSInvocationOperation 将特定对象的特定方法封装成NSOperation NSBlockOperation 将代码块封装成NSOpreation 示例: 创建NSInvocationOperation NSString* url = @"...

depaoweng2915的博客 607

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NSOperation简介

下面是根据官方文档及个人理解写的,并使用NSOperation简单实现了一个SDWebImage库类似功能的MultiImageDownloadDome有不足或错误之处欢迎指正谢谢 NSOperation 简单介绍 NSOperation 是居于objective-c对GCD封装居于面向对象的,线程执行方式;NSOperation配合NSOperationQueue也能实现多线程编程; NSOperatio也有两个核心概念操作,队列,在之前的GCD一章中介绍过GCD的核心概念是任务,队列,这两个其实是一样的

fengyuyxz的博客 958

NSOperation并发实现

关于NSOperation的基本知识,点击查看我之前转发的博客: 猛戳这里   NSOperation实现并发有两种方式: ①自定义NSOperation只需实现main方法,然后加入到NSOperationQueue ②自定义NSOperation实现start,isExecuting,isFinished,isConnurrent,,然后【operation start】 简单说下我自

一只叫花花的猪的专栏 1978

多线程编程2 - NSOperation

一、NSOperation 1.简介 NSOperation实例封装了需要执行的操作和执行操作所需的数据,并且能够以并发或非并发的方式执行这个操作。 NSOperation本身是抽象基类,因此必须使用它的子类,使用NSOperation子类的方式有2种: 1> Foundation框架提供了两个具体子类直接供我们使用:NSInvocationOperation和NSBlockOpera

M了个J 3万+

iOS开发 自定义NSOPeration

iOS多线程开发中,NSOperation是我们经常使用的,有时系统自带的两个类NSInvocationOperation和NSBlockOperation不能满足我们的需求时就需要我们自定义。 自定义NSOperation分两种,一种是自定义非并发的NSOperation,一种是定义并发的NSOperation的。下面分别介绍。 一:定义非并发的NSOperation。 定义非并发的NSO

MrZhao的博客 4640

NSOperation使用

NSOperation1.简单说明NSOperation的作⽤:配合使用NSOperation和NSOperationQueue也能实现多线程编程NSOperation和NSOperationQueue实现多线程的具体步骤:(1)先将需要执行的操作封装到一个NSOperation对象中(2)然后将NSOperation对象添加到NSOperationQueue中(3)系统会⾃动将NSOperatio

Step_Next的博客 1131

【iOS】NSOperation,NSOperationQueue

例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。提示:以下是本篇文章正文内容,下面案例可供参考我们可以通过自定义继承自NSOperation的子类,重写main或者start来定义自己的NSOperation对象。如果只是重写了main方法,有底层控制变更任务执行、完成状态以及任务退出。如果重写了start方法,需要自己控制任务状态。

weixin_61196797的博客 1425
上一篇: Error (0xc0000225) installing Windows 7 on VirtualBox
下一篇: 模拟器iPhone5测试
workhardupc100
博客等级 码龄18年 129粉丝 115原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值