lDispatchhost error什么意思#3095什

Reported by:
Milestone:
Component:
Attachments (1)
(10.6 KB) -
added by ryandesign (Ryan Schmidt) .
Download all attachments as:
Comments only
Change History (13)
by amontinari@…
amontinari@… added
follow-up:
by ryandesign (Ryan Schmidt)
amontinari@… removed
Description
modified ()
opencv removed
opencv added
changed from Error: Processing of port opencv failed to opencv: error: dispatch/dispatch.h: No such file or directory
changed from request to defect
by ryandesign (Ryan Schmidt)
Attachment
in reply to:
follow-up:
by cooljeanius (Eric Gallager)
in reply to:
follow-up:
by larryv (Lawrence Velázquez)
in reply to:
by cooljeanius (Eric Gallager)
by jmroot (Joshua Root)
changed from macports-tickets@… to stromnov@…
follow-up:
by stromnov (Andrew Stromnov)
in reply to:
by cooljeanius (Eric Gallager)
follow-up:
by cooljeanius (Eric Gallager)
by cooljeanius (Eric Gallager)
egall@… added
in reply to:
by udbraumann
by udbraumann
braumann@… added
for help on using
Download in other formats:corosync 出错,表示不解【linux吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:184,506贴子:
corosync 出错,表示不解收藏
双机互信,时间同步,解析都好着,启动也正常,使用 crm status
出现以下错误[root
~]# crm statusCould not establish cib_ro connection: Connection refused (111)ERROR: status: crm_mon (rc=107): Connection to cluster failed: Transport endpoint is not connected日志:[root@node1 ~]# tail /var/log/cluster/corosync.logAug 11 02:31:53 [7022] node1.feiyu.com
info: crm_timer_popped: Wait Timer (I_NULL) just popped (2000ms)Aug 11 02:31:53 [7022] node1.feiyu.com
info: crm_ipc_connect: Could not establish cib_shm connection: Connection refused (111)Aug 11 02:31:54 [7022] node1.feiyu.com
info: crm_ipc_connect: Could not establish cib_shm connection: Connection refused (111)Aug 11 02:31:54 [7022] node1.feiyu.com
info: do_cib_control: Could not connect to the CIB service: Transport endpoint is not connectedAug 11 02:31:54 [7022] node1.feiyu.com
warning: do_cib_control: Couldn't complete CIB registration 10 times... pause and retryAug 11 02:31:56 [7022] node1.feiyu.com
info: crm_timer_popped: Wait Timer (I_NULL) just popped (2000ms)Aug 11 02:31:56 [7022] node1.feiyu.com
info: crm_ipc_connect: Could not establish cib_shm connection: Connection refused (111)Aug 11 02:31:57 [7022] node1.feiyu.com
info: crm_ipc_connect: Could not establish cib_shm connection: Connection refused (111)Aug 11 02:31:57 [7022] node1.feiyu.com
info: do_cib_control: Could not connect to the CIB service: Transport endpoint is not connectedAug 11 02:31:57 [7022] node1.feiyu.com
warning: do_cib_control: Couldn't complete CIB registration 11 times... pause and retry邮件也收到崩溃报告了Subject: [abrt] a crash has been detected againUser-Agent: Heirloom mailx 12.4 7/29/08Content-Type: text/ charset=us-asciiStatus: Rabrt_version:
2.0.8cgroup:
/usr/libexec/pacemaker/cibexecutable:
/usr/libexec/pacemaker/cibhostname:
node1.feiyu.comkernel:
2.6.32-504.el6.i686last_occurrence: pid:
/var/lib/pacemaker/corestime:
Tue 11 Aug :51 AM PDTuid:
189username:
haclustersosreport.tar.xz: Binary file, 1068164 bytesdso_list::/lib/libaudit.so.1.0.0 audit-libs-2.3.7-5.el6.i686 (CentOS) :/lib/ld-2.12.so glibc-2.12-1.166.el6_7.1.i686 (CentOS) 网上找了半天都没有找到答案,
阿里云云市场镜像可以一键部署云服务器所需要的运行环境和个性化的软件应用,满足建站,应用开发,可视化管理等个性化需求,linux镜像让云服务器&即开即用&.
pacemaker没有启动,手动启动后,还是出现此错误
我也遇到同样的问题。百度无解!!求大神指点!!!crm(live)# statusCould not establish cib_ro connection: Connection refused (111)ERROR: status: crm_mon (rc=107): Connection to cluster failed: Transport endpoint is not connected 查看日志情况正常1 产看Corosync引擎是否启动正常grep -e &Corosync Cluster Engine& -e &configuration file& /var/log/cluster/corosync.log[MAIN
] Corosync Cluster Engine ('1.4.7'): started and ready to provide service.[MAIN
] Successfully read main configuration file '/etc/corosync/corosync.conf'.2 查看初始化节点成员通知是否正常发出grep TOTEM /var/log/cluster/corosync.log[TOTEM ] Initializing transport (UDP/IP Multicast).[TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).[TOTEM ] The network interface [192.168.1.204] is now up.[TOTEM ] Process pause detected for 704 ms, flushing membership messages.[TOTEM ] A processor joined or left the membership and a new membership was formed.3启动是否有错误产生grep ERROR: /var/log/cluster/corosync.log | grep -v unpack_resources[pcmk
] ERROR: process_ais_conf: You have configured a cluster using the Pacemaker plugin for Corosync. The plugin is not supported in this environment and will be removed very soon.[pcmk
] ERROR: process_ais_conf:
Please see Chapter 8 of 'Clusters from Scratch'() for details on using Pacemaker with CMAN[pcmk
] ERROR: pcmk_wait_dispatch: Child process cib terminated with signal 6 (pid=1511, core=true)4产看pacemaker 是否启动正常grep pcmk_startup /var/log/cluster/corosync.log[pcmk
] info: pcmk_startup: CRM: Initialized[pcmk
] Logging: Initialized pcmk_startup[pcmk
] info: pcmk_startup: Maximum core file size is: [pcmk
] info: pcmk_startup: Service: 9[pcmk
] info: pcmk_startup: Local hostname: node1.com
一样的问题 goodle 没找到
同样的问题,求解答
折腾了几个小时也没找到解决方法
这是谷歌上一个人发的信息
百度粗略翻译了下
但还是没明白
不知道有没有朋友是否看出什么提示
iptables selinux
我也遇到了这个问题,不知道什么情况,启动一个节点时,一切正常,同时启动二个节点都不正常。
同样的问题 解决办法
根据网上的资料配置的:[root
corosync]# cat
corosync.conf
| egrep -v '#'compatibiity: whitetanktotem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.85.0
mcastaddr: 239.245.4.1
mcastport: 5405
}}logging {
fileline: off
to_stderr: no
to_logfile: yes
logfile: /var/log/cluster/corosync.log
to_syslog: no
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}}service {
name: pacemaker#corosync启动时也将pacemaker启动}aisexec {#表示启动ais的功能时,以哪个用户,组的身份运行,默认为root:root这写可不用定义;
user: root
group: root}结果出现和你一样的错误,看了一下官网的资料,其他没动,就改了这些:service {
name: pacemaker#corosync启动时也将pacemaker启动
ver: 1}删了aisexec配置段然后再测试竟然好了;我把官网的说明给你贴出来吧:service {# Load the Pacemaker Cluster Resource Managername: pacemakerver: 1}The final configuration should look something like the sample in Appendix B, SampleCorosync Configuration.When run in version 1 mode, the plugin does not start the Pacemaker daemons. Insteadit just sets up the quorum and messaging interfaces needed by the rest of the stack.Starting the dameons occurs when the Pacemaker init script is invoked. This resolvestwo long standing issues:a. Forking inside a multi-threaded process like Corosync causes all sorts of pain.This has been problematic for Pacemaker as it needs a number of daemons to bespawned.b. Corosync was never designed for staggered shutdown - something previously neededin order to prevent the cluster from leaving before Pacemaker could stop allactive resources.你看看吧 ,如果也能解决最好,如果还不行,我也没办法了!
@wangy8961我的理解是:0表示pacemaker作为corosync的插件来运行,pacemaker随corosync的启动而启动;1表示pacemaker作为单一的守护进程来运行,也就是说在启动corosync后还必须手动启动pacemaker守护进程,两种情况下pacemaker应该都是corosync的插件。不过,难道还像电脑安装软件自带的插件那样有自启和手启之分?
小弟混脸熟,~混脸熟~
遇到了这个问题,有人解决了吗?
先停掉pacemaker写一个脚本杀pacemakera=0while i=$(ps -aux | grep ps | grep -v grep | awk '{print $2}');dokill $i && echo $a++done
我只搭建过http的集群
最简单的那种
登录百度帐号推荐应用python - # Error: TypeError: unbound method __init__() must be called with shape instance as first argument (got str instance instead) # - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
It's my script:
class shape:
def __init__(self, name):
self.name = name
def printMyself(self):
print 'I am a shape named %s.' % self.name
shape1 = shape(name = 'myFirstShape.')
shape2 = shape(name = 'mySecondShape.')
shape1.printMyself()
shape2.printMyself()
class polyCube(shape):
def __init__(self, name, length, width, height):
shape.__init__(name)
self.length = length
self.width = width
self.height = height
def printMyself(self):
shape.printMyself(self)
print 'I am also a cube with dimensions %.2f, %.2f, %.2f.' % (length, width, height)
class polySphere(shape):
def __init__(self, name, radius):
shape.__init__(name)
self.radius = radius
def printMyself(self):
shape.printMyself(self)
print 'I am also a sphere with dimensions of %.2f.' % (radius)
cube1 = polyCube('firstCube', 2.0, 1.0, 3.0)
cube2 = polyCube('secondCube', 3.0, 3.0, 3.0)
sphere1 = polySphere('firstSphere', 2.2)
sphere2 = polySphere('secondSphere', 3.5)
shape1 = shape('myShape')
cube1.printMyself()
cube2.printMyself()
sphere1.printMyself()
sphere2.printMyself()
# Error: TypeError: unbound method __init__() must be called with shape instance as first argument (got str instance instead) #
I don't understand.
Why I got this error message?
What's the solution?
12.3k24566
A working version of your code, i've explained the errors in comments
class shape:
def __init__(self, name):
self.name = name
def printMyself(self):
print ('I am a shape named %s.' % self.name)
shape1 = shape(name = 'myFirstShape.')
shape2 = shape(name = 'mySecondShape.')
shape1.printMyself()
shape2.printMyself()
class polyCube(shape):
def __init__(self, name, length, width, height):
shape.__init__(self,name) #pass self here, you're calling parent's __init__() explicitly so you should pass self.
self.length = length
self.width = width
self.height = height
def printMyself(self):
shape.printMyself(self)
#use self.length ,self.width instead of just length,width etc
print ('I am also a cube with dimensions %.2f, %.2f, %.2f.' % (self.length, self.width, self.height))
class polySphere(shape):
def __init__(self, name, radius):
shape.__init__(self,name) #pass self here
self.radius = radius
def printMyself(self):
shape.printMyself(self)
print ('I am also a sphere with dimensions of %.2f.' % (self.radius)) #use self.radius here
cube1 = polyCube('firstCube', 2.0, 1.0, 3.0)
cube2 = polyCube('secondCube', 3.0, 3.0, 3.0)
sphere1 = polySphere('firstSphere', 2.2)
sphere2 = polySphere('secondSphere', 3.5)
shape1 = shape('myShape')
cube1.printMyself()
cube2.printMyself()
sphere1.printMyself()
sphere2.printMyself()
157k29273343
In general, you should post the full traceback.
It makes things a lot easier to debug.
The problem (other than the indentation which I assume came from copy/paste errors) is when you call:
shape.__init__(name)
when you inherit from shape.
If you look at shape.__init__'s "prototype", it looks like shape.__init__(self,name) -- So that is what you should be using.
The error is coming because you're passing name (a string) where you should be passing self (a PolyCube and therefore also a shape due to inheritance)
Also, in python 2.x, it is good practice to always inherit from object. e.g.:
class shape(object):
This allows you to use all the goodness associated with new-style classes.
(in python 3, all classes are new-style classes)
186k35348462
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledCS里的host_error:Dispatchvser msg:lllegal user Msg 255是什么_百度知道
CS里的host_error:Dispatchvser msg:lllegal user Msg 255是什么
进入别的服务器就自动退出,然后就出现上面的英文。请高手们帮帮。
我有更好的答案
host_error:Dispatchvser信息:lllegal用户消息255退出游戏 再进试下
采纳率:22%
为您推荐:
其他类似问题
msg的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。SDWebImage源码解析之SDWebImageManager的注解
招聘信息:
&*&This&file&is&part&of&the&SDWebImage&package.
&*&(c)&Olivier&Poitrey&&*
&*&For&the&full&copyright&and&license&information,&please&view&the&LICENSE
&*&file&that&was&distributed&with&this&source&code.
#import&"SDWebImageCompat.h"
#import&"SDWebImageOperation.h"
#import&"SDWebImageDownloader.h"
#import&"SDImageCache.h"
typedef&NS_OPTIONS(NSUInteger,&SDWebImageOptions)&{
&&&&&*&By&default,&when&a&URL&fail&to&be&downloaded,&the&URL&is&blacklisted&so&the&library&won't&keep&trying.
&&&&&*&This&flag&disable&this&blacklisting.
&&&&&*默认情况下,如果一个url在下载的时候失败了,那么这个url会被加入黑名单并且library不会尝试再次下载,这个flag会阻止library把失败的url加入黑名单(简单来说如果选择了这个flag,那么即使某个url下载失败了,sdwebimage还是会尝试再次下载他.)
&&&&SDWebImageRetryFailed&=&1&<<&0,
&&&&&*&By&default,&image&downloads&are&started&during&UI&interactions,&this&flags&disable&this&feature,
&&&&&*&leading&to&delayed&download&on&UIScrollView&deceleration&for&instance.
&&&&&*默认情况下,图片会在交互发生的时候下载(例如你滑动tableview的时候),这个flag会禁止这个特性,导致的结果就是在scrollview减速的时候
&&&&&*才会开始下载(也就是你滑动的时候scrollview不下载,你手从屏幕上移走,scrollview开始减速的时候才会开始下载图片)
&&&&SDWebImageLowPriority&=&1&<<&1,
&&&&&*&This&flag&disables&on-disk&caching
&&&&&*这个flag禁止磁盘缓存,只有内存缓存
&&&&SDWebImageCacheMemoryOnly&=&1&<<&2,
&&&&&*&This&flag&enables&progressive&download,&the&image&is&displayed&progressively&during&download&as&a&browser&would&do.
&&&&&*&By&default,&the&image&is&only&displayed&once&completely&downloaded.
&&&&&*这个flag会在图片下载的时候就显示(就像你用浏览器浏览网页的时候那种图片下载,一截一截的显示(待确认))
&&&&SDWebImageProgressiveDownload&=&1&<<&3,
&&&&&*&Even&if&the&image&is&cached,&respect&the&HTTP&response&cache&control,&and&refresh&the&image&from&remote&location&if&needed.
&&&&&*&The&disk&caching&will&be&handled&by&NSURLCache&instead&of&SDWebImage&leading&to&slight&performance&degradation.
&&&&&*&This&option&helps&deal&with&images&changing&behind&the&same&request&URL,&e.g.&Facebook&graph&api&profile&pics.
&&&&&*&If&a&cached&image&is&refreshed,&the&completion&block&is&called&once&with&the&cached&image&and&again&with&the&final&image.
&&&&&*&Use&this&flag&only&if&you&can&#39;t&make&your&URLs&static&with&embeded&cache&busting&parameter.
&&&&&*这个选项的意思看的不是很懂,大意是即使一个图片缓存了,还是会重新请求.并且缓存侧略依据NSURLCache而不是SDWebImage.
&&&&SDWebImageRefreshCached&=&1&<<&4,
&&&&&*&In&iOS&4+,&continue&the&download&of&the&image&if&the&app&goes&to&background.&This&is&achieved&by&asking&the&system&for
&&&&&*&extra&time&in&background&to&let&the&request&finish.&If&the&background&task&expires&the&operation&will&be&cancelled.
&&&&&*启动后台下载,加入你进入一个页面,有一张图片正在下载这时候你让app进入后台,图片还是会继续下载(这个估计要开backgroundfetch才有用)
&&&&SDWebImageContinueInBackground&=&1&<<&5,
&&&&&*&Handles&cookies&stored&in&NSHTTPCookieStore&by&setting
&&&&&*&NSMutableURLRequest.HTTPShouldHandleCookies&=&YES;
&&&&&*可以控制存在NSHTTPCookieStore的cookies.(我没用过,等用过的人过来解释一下)
&&&&SDWebImageHandleCookies&=&1&<<&6,
&&&&&*&Enable&to&allow&untrusted&SSL&ceriticates.
&&&&&*&Useful&for&testing&purposes.&Use&with&caution&in&production.
&&&&&*允许不安全的SSL证书,在正式环境中慎用
&&&&SDWebImageAllowInvalidSSLCertificates&=&1&<<&7,
&&&&&*&By&default,&image&are&loaded&in&the&order&they&were&queued.&This&flag&move&them&to
&&&&&*&the&front&of&the&queue&and&is&loaded&immediately&instead&of&waiting&for&the&current&queue&to&be&loaded&(which&
&&&&&*&could&take&a&while).
&&&&&*默认情况下,image在装载的时候是按照他们在队列中的顺序装载的(就是先进先出).这个flag会把他们移动到队列的前端,并且立刻装载
&&&&&*而不是等到当前队列装载的时候再装载.
&&&&SDWebImageHighPriority&=&1&<<&8,
&&&&&*&By&default,&placeholder&images&are&loaded&while&the&image&is&loading.&This&flag&will&delay&the&loading
&&&&&*&of&the&placeholder&image&until&after&the&image&has&finished&loading.
&&&&&*默认情况下,占位图会在图片下载的时候显示.这个flag开启会延迟占位图显示的时间,等到图片下载完成之后才会显示占位图.(等图片显示完了我干嘛还显示占位图?或许是我理解错了?)
&&&&SDWebImageDelayPlaceholder&=&1&<<&9,
&&&&&*&We&usually&don&#39;t&call&transformDownloadedImage&delegate&method&on&animated&images,
&&&&&*&as&most&transformation&code&would&mangle&it.
&&&&&*&Use&this&flag&to&transform&them&anyway.
&&&&&*是否transform图片(没用过,还要再看,但是据我估计,是否是图片有可能方向不对需要调整方向,例如采用iPhone拍摄的照片如果不纠正方向,那么图片是向左旋转90度的.可能很多人不知道iPhone的摄像头并不是竖直的,而是向左偏了90度.具体请google.)
&&&&SDWebImageTransformAnimatedImage&=&1&<<&10,
typedef&void(^SDWebImageCompletionBlock)(UIImage&*image,&NSError&*error,&SDImageCacheType&cacheType,&NSURL&*imageURL);
typedef&void(^SDWebImageCompletionWithFinishedBlock)(UIImage&*image,&NSError&*error,&SDImageCacheType&cacheType,&BOOL&finished,&NSURL&*imageURL);
typedef&NSString&*(^SDWebImageCacheKeyFilterBlock)(NSURL&*url);
@class&SDWebImageM
@protocol&SDWebImageManagerDelegate&@optional
&*&Controls&which&image&should&be&downloaded&when&the&image&is&not&found&in&the&cache.
&*&@param&imageManager&The&current&`SDWebImageManager`
&*&@param&imageURL&&&&&The&url&of&the&image&to&be&downloaded
&*&@return&Return&NO&to&prevent&the&downloading&of&the&image&on&cache&misses.&If&not&implemented,&YES&is&implied.
&*主要作用是当缓存里没有发现某张图片的缓存时,是否选择下载这张图片(默认是yes),可以选择no,那么sdwebimage在缓存中没有找到这张图片的时候不会选择下载
-&(BOOL)imageManager:(SDWebImageManager&*)imageManager&shouldDownloadImageForURL:(NSURL&*)imageURL;
&*&Allows&to&transform&the&image&immediately&after&it&has&been&downloaded&and&just&before&to&cache&it&on&disk&and&memory.
&*&NOTE:&This&method&is&called&from&a&global&queue&in&order&to&not&to&block&the&main&thread.
&*&@param&imageManager&The&current&`SDWebImageManager`
&*&@param&image&&&&&&&&The&image&to&transform
&*&@param&imageURL&&&&&The&url&of&the&image&to&transform
&*&@return&The&transformed&image&object.
&*在图片下载完成并且还没有加入磁盘缓存或者内存缓存的时候就transform这个图片.这个方法是在异步线程执行的,防治阻塞主线程.
&*至于为什么在异步执行很简单,对一张图片纠正方向(也就是transform)是很耗资源的,一张2M大小的图片纠正方向你可以用instrument测试一下耗时.
-&(UIImage&*)imageManager:(SDWebImageManager&*)imageManager&transformDownloadedImage:(UIImage&*)image&withURL:(NSURL&*)imageURL;
&*&The&SDWebImageManager&is&the&class&behind&the&UIImageView+WebCache&category&and&likes.
&*&It&ties&the&asynchronous&downloader&(SDWebImageDownloader)&with&the&image&cache&store&(SDImageCache).
&*&You&can&use&this&class&directly&to&benefit&from&web&image&downloading&with&caching&in&another&context&than
&*&a&UIView.
&*&Here&is&a&simple&example&of&how&to&use&SDWebImageManager:
SDWebImageManager&*manager&=&[SDWebImageManager&sharedManager];
[manager&downloadImageWithURL:imageURL
&&&&&&&&&&&&&&&&&&&&&&options:0
&&&&&&&&&&&&&&&&&&&&&progress:nil
&&&&&&&&&&&&&&&&&&&&completed:^(UIImage&*image,&NSError&*error,&SDImageCacheType&cacheType,&BOOL&finished,&NSURL&*imageURL)&{
&&&&&&&&&&&&&&&&&&&&&&&&if&(image)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&//&do&something&with&image
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&}];
&*&@endcode
&*这一段是阐述SDWebImageManager是干嘛的.其实UIImageView+WebCache这个category背后执行操作的就是这个SDWebImageManager.他会绑定一个下载器也就是SDWebImageDownloader和一个缓存SDImageCache.后面的大意应该是讲你可以直接使用一个其他上下文环境的SDWebImageManager,而不是仅仅限于一个UIView.
@interface&SDWebImageManager&:&NSObject
@property&(weak,&nonatomic)&id&&
&*如同上文所说,一个SDWebImageManager会绑定一个imageCache和一个下载器.
@property&(strong,&nonatomic,&readonly)&SDImageCache&*imageC
@property&(strong,&nonatomic,&readonly)&SDWebImageDownloader&*imageD
&*&The&cache&filter&is&a&block&used&each&time&SDWebImageManager&need&to&convert&an&URL&into&a&cache&key.&This&can
&*&be&used&to&remove&dynamic&part&of&an&image&URL.
&*&The&following&example&sets&a&filter&in&the&application&delegate&that&will&remove&any&query-string&from&the
&*&URL&before&to&use&it&as&a&cache&key:
[[SDWebImageManager&sharedManager]&setCacheKeyFilter:^(NSURL&*url)&{
&&&&url&=&[[NSURL&alloc]&initWithScheme:url.scheme&host:url.host&path:url.path];
&&&&return&[url&absoluteString];
&*&@endcode
&*&这个cacheKeyFilter是干嘛的呢?很简单.1他是一个block.2.这个block的作用就是生成一个image的key.因为sdwebimage的缓存原理你可以当成是一个字典,每一个字典的value就是一张image,那么这个value对应的key是什么呢?就是cacheKeyFilter根据某个规则对这个图片的url做一些操作生成的.上面的示例就显示了怎么利用这个block把image的url重新组合生成一个key.以后当sdwebimage检测到你
@property&(nonatomic,&copy)&SDWebImageCacheKeyFilterBlock&cacheKeyF
&*&Returns&global&SDWebImageManager&instance.
&*&@return&SDWebImageManager&shared&instance
&*这个不用我解释了吧,生成一个SDWebImagemanager的单例.
+&(SDWebImageManager&*)sharedM
&*&Downloads&the&image&at&the&given&URL&if&not&present&in&cache&or&return&the&cached&version&otherwise.
&*&从给定的URL中下载一个之前没有被缓存的Image.
&*&@param&url&&&&&&&&&&&&The&URL&to&the&image
&*&@param&options&&&&&&&&A&mask&to&specify&options&to&use&for&this&request
&*&@param&progressBlock&&A&block&called&while&image&is&downloading
&*&@param&completedBlock&A&block&called&when&operation&has&been&completed.
&*&&&This&parameter&is&required.
&*&&&This&block&has&no&return&value&and&takes&the&requested&UIImage&as&first&parameter.
&*&&&In&case&of&error&the&image&parameter&is&nil&and&the&second&parameter&may&contain&an&NSError.
&*&&&The&third&parameter&is&an&`SDImageCacheType`&enum&indicating&if&the&image&was&retrived&from&the&local&cache
&*&&&or&from&the&memory&cache&or&from&the&network.
&*&&&The&last&parameter&is&set&to&NO&when&the&SDWebImageProgressiveDownload&option&is&used&and&the&image&is&
&*&&&downloading.&This&block&is&thus&called&repetidly&with&a&partial&image.&When&image&is&fully&downloaded,&the
&*&&&block&is&called&a&last&time&with&the&full&image&and&the&last&parameter&set&to&YES.
&*&@return&Returns&an&NSObject&conforming&to&SDWebImageOperation.&Should&be&an&instance&of&SDWebImageDownloaderOperation
&*&这个方法主要就是SDWebImage下载图片的方法了.&&
&*&第一个参数是必须要的,就是image的url
&*&第二个参数就是我们上面的Options,你可以定制化各种各样的操作.详情参上.&
&*&第三个参数是一个回调block,用于图片在下载过程中的回调.(英文注释应该是有问题的.)
&*&第四个参数是一个下载完成的回调.会在图片下载完成后回调.
&*&返回值是一个NSObject类,并且这个NSObject类是conforming一个协议这个协议叫做SDWebImageOperation,这个协议很简单,就是一个cancel掉operation的协议.
-&(id&)downloadImageWithURL:(NSURL&*)url
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options:(SDWebImageOptions)options
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&progress:(SDWebImageDownloaderProgressBlock)progressBlock
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&completed:(SDWebImageCompletionWithFinishedBlock)completedB
&*&Saves&image&to&cache&for&given&URL
&*&@param&image&The&image&to&cache
&*&@param&url&&&The&URL&to&the&image
&*&将图片存入cache的方法,类似于字典的setValue:&forKey:
-&(void)saveImageToCache:(UIImage&*)image&forURL:(NSURL&*)
&*&Cancel&all&current&opreations
&*取消掉当前所有的下载图片的operation
-&(void)cancelA
&*&Check&one&or&more&operations&running
&*&check一下是否有一个或者多个operation正在执行(简单来说就是check是否有图片在下载)
-&(BOOL)isR
&*&&Check&if&image&has&already&been&cached
&*&&@param&url&image&url
&*&&@return&if&the&image&was&already&cached
&*&通过一个image的url是否已经存在,如果存在返回yes,否则返回no
-&(BOOL)cachedImageExistsForURL:(NSURL&*)
&*&&Check&if&image&has&already&been&cached&on&disk&only
&*&&@param&url&image&url
&*&&@return&if&the&image&was&already&cached&(disk&only)
&*&检测一个image是否已经被缓存到磁盘(是否存且仅存在disk里).
-&(BOOL)diskImageExistsForURL:(NSURL&*)
&*&&Async&check&if&image&has&already&been&cached
&*&&@param&url&&&&&&&&&&&&&&image&url
&*&&@param&completionBlock&&the&block&to&be&executed&when&the&check&is&finished
&*&&@note&the&completion&block&is&always&executed&on&the&main&queue
&*&如果检测到图片已经被缓存,那么执行回调block.这个block会永远执行在主线程.也就是你可以在这个回调block里更新ui.
-&(void)cachedImageExistsForURL:(NSURL&*)url
&&&&&&&&&&&&&&&&&&&&&completion:(SDWebImageCheckCacheCompletionBlock)completionB
&*&&Async&check&if&image&has&already&been&cached&on&disk&only
&*&&@param&url&&&&&&&&&&&&&&image&url
&*&&@param&completionBlock&&the&block&to&be&executed&when&the&check&is&finished
&*&&@note&the&completion&block&is&always&executed&on&the&main&queue
&*&如果检测到图片已经被缓存在磁盘(存且仅存在disk),那么执行回调block.这个block会永远执行在主线程.也就是你可以在这个回调block里更新ui.
-&(void)diskImageExistsForURL:(NSURL&*)url
&&&&&&&&&&&&&&&&&&&completion:(SDWebImageCheckCacheCompletionBlock)completionB
&*Return&the&cache&key&for&a&given&URL
&*&通过image的url返回image存在缓存里的key.有人会问了,为什么不直接把图片的url当做image的key来使用呢?而是非要对url做一些处理才能当做key.我的解释是,我也不太清楚.可能为了防止重复吧.
-&(NSString&*)cacheKeyForURL:(NSURL&*)
#pragma&mark&-&Deprecated
typedef&void(^SDWebImageCompletedBlock)(UIImage&*image,&NSError&*error,&SDImageCacheType&cacheType)&__deprecated_msg("Block&type&deprecated.&Use&`SDWebImageCompletionBlock`");
typedef&void(^SDWebImageCompletedWithFinishedBlock)(UIImage&*image,&NSError&*error,&SDImageCacheType&cacheType,&BOOL&finished)&__deprecated_msg("Block&type&deprecated.&Use&`SDWebImageCompletionWithFinishedBlock`");
//&已被废弃
@interface&SDWebImageManager&(Deprecated)
&*&&Downloads&the&image&at&the&given&URL&if&not&present&in&cache&or&return&the&cached&version&otherwise.
&*&&@deprecated&This&method&has&been&deprecated.&Use&`downloadImageWithURL:options:progress:completed:`
-&(id&)downloadWithURL:(NSURL&*)url
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options:(SDWebImageOptions)options
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&progress:(SDWebImageDownloaderProgressBlock)progressBlock
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&completed:(SDWebImageCompletedWithFinishedBlock)completedBlock&__deprecated_msg("Method&deprecated.&Use&`downloadImageWithURL:options:progress:completed:`");
&*&This&file&is&part&of&the&SDWebImage&package.
&*&(c)&Olivier&Poitrey&&*
&*&For&the&full&copyright&and&license&information,&please&view&the&LICENSE
&*&file&that&was&distributed&with&this&source&code.
#import&"SDWebImageManager.h"
#import&//&内部类.
@interface&SDWebImageCombinedOperation&:&NSObject&@property&(assign,&nonatomic,&getter&=&isCancelled)&BOOL&
@property&(copy,&nonatomic)&SDWebImageNoParamsBlock&cancelB
@property&(strong,&nonatomic)&NSOperation&*cacheO
@interface&SDWebImageManager&()
@property&(strong,&nonatomic,&readwrite)&SDImageCache&*imageC
@property&(strong,&nonatomic,&readwrite)&SDWebImageDownloader&*imageD
@property&(strong,&nonatomic)&NSMutableSet&*failedURLs;
@property&(strong,&nonatomic)&NSMutableArray&*runningO
@implementation&SDWebImageManager
//&利用disptach_once&特性生成一个单例,用烂了的方法.不赘述.
+&(id)sharedManager&{
&&&&static&dispatch_once_t&
&&&&static&id&
&&&&dispatch_once(&once,&^{
&&&&&&&&instance&=&[self&new];
&&&&return&
//&初始化方法.
//&1.获得一个SDImageCache的单例.2.获取一个SDWebImageDownloader的单例.3.新建一个MutableSet来存储下载失败的url.
//&4.新建一个用来存储下载operation的可变数组.
//&为什么不用MutableArray储存下载失败的URL?
//&因为NSSet类有一个特性,就是Hash.实际上NSSet是一个哈希表,哈希表比数组优秀的地方是什么呢?就是查找速度快.查找同样一个元素,哈希表只需要通过key
//&即可取到,而数组至少需要遍历依次.因为SDWebImage里有关失败URL的业务需求是,一个失败的URL只需要储存一次.这样的话Set自然比Array更合适.
-&(id)init&{
&&&&if&((self&=&[super&init]))&{
&&&&&&&&_imageCache&=&[self&createCache];
&&&&&&&&_imageDownloader&=&[SDWebImageDownloader&sharedDownloader];
&&&&&&&&_failedURLs&=&[NSMutableSet&new];
&&&&&&&&_runningOperations&=&[NSMutableArray&new];
&&&&return&
//&获取一个cache的单例
-&(SDImageCache&*)createCache&{
&&&&return&[SDImageCache&sharedImageCache];
//&利用Image的URL生成一个缓存时需要的key.
//&这里有两种情况,第一种是如果检测到cacheKeyFilter不为空时,利用cacheKeyFilter来处理URL生成一个key.
//&如果为空,那么直接返回URL的string内容,当做key.
-&(NSString&*)cacheKeyForURL:(NSURL&*)url&{
&&&&if&(self.cacheKeyFilter)&{
&&&&&&&&return&self.cacheKeyFilter(url);
&&&&else&{
&&&&&&&&return&[url&absoluteString];
//&检测一张图片是否已被缓存.
//&首先检测内存缓存是否存在这张图片,如果已有,直接返回yes.
//&如果内存缓存里没有这张图片,那么调用diskImageExistsWithKey这个方法去硬盘缓存里找
-&(BOOL)cachedImageExistsForURL:(NSURL&*)url&{
&&&&NSString&*key&=&[self&cacheKeyForURL:url];
&&&&if&([self.imageCache&imageFromMemoryCacheForKey:key]&!=&nil)&return&YES;
&&&&return&[self.imageCache&diskImageExistsWithKey:key];
//&检测硬盘里是否缓存了图片
-&(BOOL)diskImageExistsForURL:(NSURL&*)url&{
&&&&NSString&*key&=&[self&cacheKeyForURL:url];
&&&&return&[self.imageCache&diskImageExistsWithKey:key];
//&首先生成一个用来cache&住Image的key(利用key的url生成)
//&然后检测内存缓存里是否已经有这张图片
//&如果已经被缓存,那么再主线程里回调block
//&如果没有检测到,那么调用diskImageExistsWithKey,这个方法会在异步线程里,将图片存到硬盘,当然在存图之前也会检测是否已在硬盘缓存图片.
-&(void)cachedImageExistsForURL:(NSURL&*)url
&&&&&&&&&&&&&&&&&&&&&completion:(SDWebImageCheckCacheCompletionBlock)completionBlock&{
&&&&NSString&*key&=&[self&cacheKeyForURL:url];
&&&&BOOL&isInMemoryCache&=&([self.imageCache&imageFromMemoryCacheForKey:key]&!=&nil);
&&&&if&(isInMemoryCache)&{
&&&&&&&&//&making&sure&we&call&the&completion&block&on&the&main&queue
&&&&&&&&dispatch_async(dispatch_get_main_queue(),&^{
&&&&&&&&&&&&if&(completionBlock)&{
&&&&&&&&&&&&&&&&completionBlock(YES);
&&&&&&&&&&&&}
&&&&&&&&});
&&&&[self.imageCache&diskImageExistsWithKey:key&completion:^(BOOL&isInDiskCache)&{
&&&&&&&&//&the&completion&block&of&checkDiskCacheForImageWithKey:completion:&is&always&called&on&the&main&queue,&no&need&to&further&dispatch
&&&&&&&&if&(completionBlock)&{
&&&&&&&&&&&&completionBlock(isInDiskCache);
//将图片存入硬盘
-&(void)diskImageExistsForURL:(NSURL&*)url
&&&&&&&&&&&&&&&&&&&completion:(SDWebImageCheckCacheCompletionBlock)completionBlock&{
&&&&NSString&*key&=&[self&cacheKeyForURL:url];
&&&&[self.imageCache&diskImageExistsWithKey:key&completion:^(BOOL&isInDiskCache)&{
&&&&&&&&//&the&completion&block&of&checkDiskCacheForImageWithKey:completion:&is&always&called&on&the&main&queue,&no&need&to&further&dispatch
&&&&&&&&if&(completionBlock)&{
&&&&&&&&&&&&completionBlock(isInDiskCache);
//&通过url建立一个operation用来下载图片.
-&(id&)downloadImageWithURL:(NSURL&*)url
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options:(SDWebImageOptions)options
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&progress:(SDWebImageDownloaderProgressBlock)progressBlock
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&completed:(SDWebImageCompletionWithFinishedBlock)completedBlock&{
&&&&//&Invoking&this&method&without&a&completedBlock&is&pointless
&&&&NSAssert(completedBlock&!=&nil,&@"If&you&mean&to&prefetch&the&image,&use&-[SDWebImagePrefetcher&prefetchURLs]&instead");
&&&&//&Very&common&mistake&is&to&send&the&URL&using&NSString&object&instead&of&NSURL.&For&some&strange&reason,&XCode&won&#39;t
&&&&//&throw&any&warning&for&this&type&mismatch.&Here&we&failsafe&this&error&by&allowing&URLs&to&be&passed&as&NSString.
&&&&if&([url&isKindOfClass:NSString.class])&{
&&&&&&&&url&=&[NSURL&URLWithString:(NSString&*)url];
&&&&//&Prevents&app&crashing&on&argument&type&error&like&sending&NSNull&instead&of&NSURL
&&&&if&(![url&isKindOfClass:NSURL.class])&{
&&&&&&&&url&=&
&&&&__block&SDWebImageCombinedOperation&*operation&=&[SDWebImageCombinedOperation&new];
&&&&__weak&SDWebImageCombinedOperation&*weakOperation&=&
&&&&BOOL&isFailedUrl&=&NO;
&&&&//&创建一个互斥锁防止现在有别的线程修改failedURLs.
&&&&//&判断这个url是否是fail过的.如果url&failed过的那么isFailedUrl就是true
&&&&@synchronized&(self.failedURLs)&{
&&&&&&&&isFailedUrl&=&[self.failedURLs&containsObject:url];
&&&&//&如果url不存在那么直接返回一个block,如果url存在.那么继续进行判断.
&&&&//&options与SDWebImageRetryFailed这个option进行按位与操作.判断用户的options里是否有retry这个option.
&&&&//&如果用户的options里没有retry这个选项并且isFaileUrl&是true.那么就回调一个error的block.
&&&&if&(!url&||&(!(options&&&SDWebImageRetryFailed)&&&&isFailedUrl))&{
&&&&&&&&dispatch_main_sync_safe(^{
&&&&&&&&&&&&NSError&*error&=&[NSError&errorWithDomain:NSURLErrorDomain&code:NSURLErrorFileDoesNotExist&userInfo:nil];
&&&&&&&&&&&&completedBlock(nil,&error,&SDImageCacheTypeNone,&YES,&url);
&&&&&&&&});
&&&&&&&&return&
&&&&//&创建一个互斥锁防止现在有别的线程修改runningOperations.
&&&&@synchronized&(self.runningOperations)&{
&&&&&&&&[self.runningOperations&addObject:operation];
&&&&NSString&*key&=&[self&cacheKeyForURL:url];
&&&&//&cacheOperation应该是一个用来下载图片并且缓存的operation
&&&&operation.cacheOperation&=&[self.imageCache&queryDiskCacheForKey:key&done:^(UIImage&*image,&SDImageCacheType&cacheType)&{
&&&&&&&&//&判断operation这时候有没有执行cancel操作,如果cancel掉了就把这个operation从我们的operation数组里remove掉然后return
&&&&&&&&if&(operation.isCancelled)&{
&&&&&&&&&&&&@synchronized&(self.runningOperations)&{
&&&&&&&&&&&&&&&&[self.runningOperations&removeObject:operation];
&&&&&&&&&&&&}
&&&&&&&&&&&&
&&&&&&&&if&((!image&||&options&&&SDWebImageRefreshCached)&&&&(![self.delegate&respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)]&||&[self.delegate&imageManager:self&shouldDownloadImageForURL:url]))&{
&&&&&&&&&&&&if&(image&&&&options&&&SDWebImageRefreshCached)&{
&&&&&&&&&&&&&&&&dispatch_main_sync_safe(^{
&&&&&&&&&&&&&&&&&&&&//&If&image&was&found&in&the&cache&bug&SDWebImageRefreshCached&is&provided,&notify&about&the&cached&image
&&&&&&&&&&&&&&&&&&&&//&AND&try&to&re-download&it&in&order&to&let&a&chance&to&NSURLCache&to&refresh&it&from&server.
&&&&&&&&&&&&&&&&&&&&completedBlock(image,&nil,&cacheType,&YES,&url);
&&&&&&&&&&&&&&&&});
&&&&&&&&&&&&}
&&&&&&&&&&&&//&download&if&no&image&or&requested&to&refresh&anyway,&and&download&allowed&by&delegate
&&&&&&&&&&&&//&下面都是判断我们的options里包含哪些SDWebImageOptions,然后给我们的downloaderOptions相应的添加对应的SDWebImageDownloaderOptions.&downloaderOptions&|=&SDWebImageDownloaderLowPriority这种表达式的意思等同于
&&&&&&&&&&&&//&downloaderOptions&=&downloaderOptions&|&SDWebImageDownloaderLowPriority
&&&&&&&&&&&&SDWebImageDownloaderOptions&downloaderOptions&=&0;
&&&&&&&&&&&&if&(options&&&SDWebImageLowPriority)&downloaderOptions&|=&SDWebImageDownloaderLowP
&&&&&&&&&&&&if&(options&&&SDWebImageProgressiveDownload)&downloaderOptions&|=&SDWebImageDownloaderProgressiveD
&&&&&&&&&&&&if&(options&&&SDWebImageRefreshCached)&downloaderOptions&|=&SDWebImageDownloaderUseNSURLC
&&&&&&&&&&&&if&(options&&&SDWebImageContinueInBackground)&downloaderOptions&|=&SDWebImageDownloaderContinueInB
&&&&&&&&&&&&if&(options&&&SDWebImageHandleCookies)&downloaderOptions&|=&SDWebImageDownloaderHandleC
&&&&&&&&&&&&if&(options&&&SDWebImageAllowInvalidSSLCertificates)&downloaderOptions&|=&SDWebImageDownloaderAllowInvalidSSLC
&&&&&&&&&&&&if&(options&&&SDWebImageHighPriority)&downloaderOptions&|=&SDWebImageDownloaderHighP
&&&&&&&&&&&&if&(image&&&&options&&&SDWebImageRefreshCached)&{
&&&&&&&&&&&&&&&&//&force&progressive&off&if&image&already&cached&but&forced&refreshing
&&&&&&&&&&&&&&&&downloaderOptions&&=&~SDWebImageDownloaderProgressiveD
&&&&&&&&&&&&&&&&//&ignore&image&read&from&NSURLCache&if&image&if&cached&but&force&refreshing
&&&&&&&&&&&&&&&&downloaderOptions&|=&SDWebImageDownloaderIgnoreCachedR
&&&&&&&&&&&&}
&&&&&&&&&&&&//&调用imageDownloader去下载image并且返回执行这个request的download的operation
&&&&&&&&&&&&id&&subOperation&=&[self.imageDownloader&downloadImageWithURL:url&options:downloaderOptions&progress:progressBlock&completed:^(UIImage&*downloadedImage,&NSData&*data,&NSError&*error,&BOOL&finished)&{
&&&&&&&&&&&&&&&&if&(weakOperation.isCancelled)&{
&&&&&&&&&&&&&&&&&&&&//&Do&nothing&if&the&operation&was&cancelled
&&&&&&&&&&&&&&&&&&&&//&See&#699&for&more&details
&&&&&&&&&&&&&&&&&&&&//&if&we&would&call&the&completedBlock,&there&could&be&a&race&condition&between&this&block&and&another&completedBlock&for&the&same&object,&so&if&this&one&is&called&second,&we&will&overwrite&the&new&data
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&else&if&(error)&{
&&&&&&&&&&&&&&&&&&&&dispatch_main_sync_safe(^{
&&&&&&&&&&&&&&&&&&&&&&&&if&(!weakOperation.isCancelled)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&completedBlock(nil,&error,&SDImageCacheTypeNone,&finished,&url);
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&});
&&&&&&&&&&&&&&&&&&&&if&(error.code&!=&NSURLErrorNotConnectedToInternet&&&&error.code&!=&NSURLErrorCancelled&&&&error.code&!=&NSURLErrorTimedOut)&{
&&&&&&&&&&&&&&&&&&&&&&&&@synchronized&(self.failedURLs)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&[self.failedURLs&addObject:url];
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&else&{
&&&&&&&&&&&&&&&&&&&&if&((options&&&SDWebImageRetryFailed))&{
&&&&&&&&&&&&&&&&&&&&&&&&@synchronized&(self.failedURLs)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&[self.failedURLs&removeObject:url];
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&BOOL&cacheOnDisk&=&!(options&&&SDWebImageCacheMemoryOnly);
&&&&&&&&&&&&&&&&&&&&if&(options&&&SDWebImageRefreshCached&&&&image&&&&!downloadedImage)&{
&&&&&&&&&&&&&&&&&&&&&&&&//&Image&refresh&hit&the&NSURLCache&cache,&do&not&call&the&completion&block
&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&else&if&(downloadedImage&&&&(!downloadedImage.images&||&(options&&&SDWebImageTransformAnimatedImage))&&&&[self.delegate&respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)])&{
&&&&&&&&&&&&&&&&&&&&&&&&dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,&0),&^{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&UIImage&*transformedImage&=&[self.delegate&imageManager:self&transformDownloadedImage:downloadedImage&withURL:url];
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(transformedImage&&&&finished)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&BOOL&imageWasTransformed&=&![transformedImage&isEqual:downloadedImage];
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&[self.imageCache&storeImage:transformedImage&recalculateFromImage:imageWasTransformed&imageData:data&forKey:key&toDisk:cacheOnDisk];
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&dispatch_main_sync_safe(^{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(!weakOperation.isCancelled)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&completedBlock(transformedImage,&nil,&SDImageCacheTypeNone,&finished,&url);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&});
&&&&&&&&&&&&&&&&&&&&&&&&});
&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&else&{
&&&&&&&&&&&&&&&&&&&&&&&&if&(downloadedImage&&&&finished)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&[self.imageCache&storeImage:downloadedImage&recalculateFromImage:NO&imageData:data&forKey:key&toDisk:cacheOnDisk];
&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&dispatch_main_sync_safe(^{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(!weakOperation.isCancelled)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&completedBlock(downloadedImage,&nil,&SDImageCacheTypeNone,&finished,&url);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&});
&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&if&(finished)&{
&&&&&&&&&&&&&&&&&&&&@synchronized&(self.runningOperations)&{
&&&&&&&&&&&&&&&&&&&&&&&&[self.runningOperations&removeObject:operation];
&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&}];
&&&&&&&&&&&&operation.cancelBlock&=&^{
&&&&&&&&&&&&&&&&[subOperation&cancel];
&&&&&&&&&&&&&&&&@synchronized&(self.runningOperations)&{
&&&&&&&&&&&&&&&&&&&&[self.runningOperations&removeObject:weakOperation];
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&};
&&&&&&&&else&if&(image)&{
&&&&&&&&&&&&dispatch_main_sync_safe(^{
&&&&&&&&&&&&&&&&if&(!weakOperation.isCancelled)&{
&&&&&&&&&&&&&&&&&&&&completedBlock(image,&nil,&cacheType,&YES,&url);
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&});
&&&&&&&&&&&&@synchronized&(self.runningOperations)&{
&&&&&&&&&&&&&&&&[self.runningOperations&removeObject:operation];
&&&&&&&&&&&&}
&&&&&&&&else&{
&&&&&&&&&&&&//&Image&not&in&cache&and&download&disallowed&by&delegate
&&&&&&&&&&&&dispatch_main_sync_safe(^{
&&&&&&&&&&&&&&&&if&(!weakOperation.isCancelled)&{
&&&&&&&&&&&&&&&&&&&&completedBlock(nil,&nil,&SDImageCacheTypeNone,&YES,&url);
&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&});
&&&&&&&&&&&&@synchronized&(self.runningOperations)&{
&&&&&&&&&&&&&&&&[self.runningOperations&removeObject:operation];
&&&&&&&&&&&&}
&&&&return&
-&(void)saveImageToCache:(UIImage&*)image&forURL:(NSURL&*)url&{
&&&&if&(image&&&&url)&{
&&&&&&&&NSString&*key&=&[self&cacheKeyForURL:url];
&&&&&&&&[self.imageCache&storeImage:image&forKey:key&toDisk:YES];
//&cancel掉所有正在执行的operation
-&(void)cancelAll&{
&&&&@synchronized&(self.runningOperations)&{
&&&&&&&&NSArray&*copiedOperations&=&[self.runningOperations&copy];
&&&&&&&&[copiedOperations&makeObjectsPerformSelector:@selector(cancel)];
&&&&&&&&[self.runningOperations&removeObjectsInArray:copiedOperations];
//&判断是否有正在运行的operation
-&(BOOL)isRunning&{
&&&&return&self.runningOperations.count&>&0;
@implementation&SDWebImageCombinedOperation
-&(void)setCancelBlock:(SDWebImageNoParamsBlock)cancelBlock&{
&&&&//&check&if&the&operation&is&already&cancelled,&then&we&just&call&the&cancelBlock
&&&&if&(self.isCancelled)&{
&&&&&&&&if&(cancelBlock)&{
&&&&&&&&&&&&cancelBlock();
&&&&&&&&_cancelBlock&=&&//&don&#39;t&forget&to&nil&the&cancelBlock,&otherwise&we&will&get&crashes
&&&&}&else&{
&&&&&&&&_cancelBlock&=&[cancelBlock&copy];
-&(void)cancel&{
&&&&self.cancelled&=&YES;
&&&&if&(self.cacheOperation)&{
&&&&&&&&[self.cacheOperation&cancel];
&&&&&&&&self.cacheOperation&=&
&&&&if&(self.cancelBlock)&{
&&&&&&&&self.cancelBlock();
&&&&&&&&//&TODO:&this&is&a&temporary&fix&to&#809.
&&&&&&&&//&Until&we&can&figure&the&exact&cause&of&the&crash,&going&with&the&ivar&instead&of&the&setter
//&&&&&&&&self.cancelBlock&=&
&&&&&&&&_cancelBlock&=&
@implementation&SDWebImageManager&(Deprecated)
//&deprecated&method,&uses&the&non&deprecated&method
//&adapter&for&the&completion&block
-&(id&)downloadWithURL:(NSURL&*)url&options:(SDWebImageOptions)options&progress:(SDWebImageDownloaderProgressBlock)progressBlock&completed:(SDWebImageCompletedWithFinishedBlock)completedBlock&{
&&&&return&[self&downloadImageWithURL:url
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&options:options
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&progress:progressBlock
&&&&&&&&&&&&&&&&&&&&&&&&&&&&completed:^(UIImage&*image,&NSError&*error,&SDImageCacheType&cacheType,&BOOL&finished,&NSURL&*imageURL)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if&(completedBlock)&{
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&completedBlock(image,&error,&cacheType,&finished);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&}];
@end下面来简单的解释一下OC里枚举的两种类型.NS_ENUM和NS_OPTIONS本质上是一样的都是枚举.我举个例子.typedef&NS_ENUM(NSInteger,&UIViewAnimationTransition)&{
&&&&UIViewAnimationTransitionNone,
&&&&UIViewAnimationTransitionFlipFromLeft,
&&&&UIViewAnimationTransitionFlipFromRight,
&&&&UIViewAnimationTransitionCurlUp,
&&&&UIViewAnimationTransitionCurlDown,
};typedef&NS_OPTIONS(NSUInteger,&UIViewAutoresizing)&{
&&&&UIViewAutoresizingNone&&&&&&&&&&&&&&&&&=&0,
&&&&UIViewAutoresizingFlexibleLeftMargin&&&=&1&<<&0,
&&&&UIViewAutoresizingFlexibleWidth&&&&&&&&=&1&<<&1,
&&&&UIViewAutoresizingFlexibleRightMargin&&=&1&<<&2,
&&&&UIViewAutoresizingFlexibleTopMargin&&&&=&1&<<&3,
&&&&UIViewAutoresizingFlexibleHeight&&&&&&&=&1&<<&4,
&&&&UIViewAutoresizingFlexibleBottomMargin&=&1&<<&5
};应该可以看出一些苗头.NS_ENUM这种声明出来的东西大部分是单选. NS_OPTIONS声明出来的大部分是多选.像UIViewAnimationTransition这种在用的时候肯定是只能选一种效果,你要么从左翻到右,要么从右翻到左,你做动画的时候总不能同一时刻让他同时从左到右,又从右到左翻,对吧.而UIViewAutosizing就不一样了.我要是让子view的宽高和父View一样,那么autoviewsizing的选项肯定是类似于这种.UIViewAutoresizingFlexibleWidth &| UIViewAutoresizingFlexibleHeight没错吧,意思就是两个options的我都得选才行.那么如果有个场景让我判断当前的view的Autoresizing有哪几个.我怎么判断呢?很简单.用按位与操作就行了.假设 autoResizings = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightM我们判断autoResizings里是否有UIViewAutoresizingFlexibleLeftMargin的时候只需要if(autoResizings & UIViewAutoresizingFlexibleLeftMargin)是否为true就可以了.用二进制表示的话(这里不用care NSUInteger到底是几位的.就表示这么个意思)UIViewAutoresizingFlexibleLeftMargin&=&
UIViewAutoresizingFlexibleWidth&=&
UIViewAutoresizingFlexibleRightMargin&=&所以根据上面的表达式,我们的autoResizings = .那么执行按位与操作是这样的.&
结果就是,为true.表示含有这个选项.
微信扫一扫
订阅每日移动开发及APP推广热点资讯公众号:CocoaChina
您还没有登录!请或
点击量4849点击量4404点击量3835点击量3456点击量3217点击量3180点击量3133点击量2980点击量2812
&2016 Chukong Technologies,Inc.
京公网安备89}

我要回帖

更多关于 syntax error什么意思 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信