我是swift的新手,我实现了一个演示,其中我有多个对象的字典,其中有一些uiimage对象。
我如何区分uiimage对象?我正在使用isKindClass,但它对我不起作用,并且给出错误,例如"' AnyObject'剂量不具有成员名称isKindOfClass"
代码就像这样
func initURLConnectionWithRequest(requestUrl:NSURL,apiTag:NSInteger,paramDic:NSDictionary,obj:NSObject) ->IMDRequest
{
var newRequest = IMDRequest()
request1 = newRequest;
self.tag=apiTag
var request = NSMutableURLRequest(URL: requestUrl)
var timeInterval = NSTimeInterval(60)
request.timeoutInterval = timeInterval
request.HTTPMethod = "POST"
var strBoundry = "---------------------------14737809831466499882746641449"
var contentType = "multipart/form-data; boundary=\(strBoundry)"
request.addValue(contentType, forHTTPHeaderField:"Content-Type")
var bodyData = NSMutableData()
var arrParamKey = paramDic.allKeys
for var i = 0; i<arrParamKey.count; i++
{
if (paramDic.objectForKey(arrParamKey[i]).isKindOfClass(UIImage))
{
}
}
urlConnection = NSURLConnection(request: request, delegate: self, startImmediately: false)!
self.senderObj = obj;
urlConnection.start()
self.isResponseReceived = false
return request1;
}
答案 0 :(得分:0)
如果你想检查天气是你想要与否的类型变量,或者它是否符合某些协议,那么你可以使用如下。请参考
var abc = ...
if abc is <UIImage> {
//the variable is of type <UIImage>
} else {
//variable is not of type <UIImage>
}
这与Objective-C中的isKindOfClass相同。
希望这会对你有所帮助。