该接口位于System.Diagnostics.SymbolStore.ISymbolScope中,它具有我要使用的方法。但是我似乎无法将其实例化为一个对象。我似乎没有可供选择的班级选择。如何创建此实例?谢谢。
答案 0 :(得分:0)
您不能直接实例化任何接口。对于ISymbolScope,您需要执行与下面的代码所示类似的操作,在该代码中,您还需要引用“使用Microsoft.Samples.Debugging.CorSymbolStore.SymbolAccess;”
func loadCards() {
// shortcuts
if valueArray.count > 0 {
let capCount = (valueArray.count > MAX_BUFFER_SIZE) ? MAX_BUFFER_SIZE : valueArray.count
for (i,value) in valueArray.enumerated() {
let newCard = createTinderCard(at: i,value : value as! NSDictionary )
allCardsArray.append(newCard)
if i < capCount {
currentLoadedCardsArray.append(newCard)
}
}
for (i,_) in currentLoadedCardsArray.enumerated() {
if i > 0 {
viewTinderBackGround.insertSubview(currentLoadedCardsArray[i], belowSubview: currentLoadedCardsArray[i - 1])
}else {
viewTinderBackGround.addSubview(currentLoadedCardsArray[i])
}
}
animateCardAfterSwiping()
perform(#selector(loadInitialDummyAnimation), with: nil, afterDelay: 1.0)
}
let username = user!["username"] as! String
let url = URL(string: "http://localhost/shotsCenter.php")! // url path to users.php file
var request = URLRequest(url: url) // create request to work with users.php file
request.httpMethod = "POST" // method of passing inf to users.php
let body = "username=\(username)" // body that passes inf to users.php
request.httpBody = body.data(using: .utf8) // convert str to utf8 str - supports all languages
// launch session
URLSession.shared.dataTask(with: request) { data, response, error in
// getting main queue of proceeding inf to communicate back, in another way it will do it in background
// and user will no see changes :)
DispatchQueue.main.async(execute: {
if error == nil {
do {
// declare json var to store $returnArray info we got users.php
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? [String: AnyObject]
self.valueArray.removeAll(keepingCapacity: false)
// delcare new secure var to store json
guard let parseJSON = json else {
print("Error while parsing")
return
}
// declare new secure var to store $returnArray["users"]
guard let parseUSERS = parseJSON["users"] else {
print(parseJSON["message"])
return
}
// append $returnArray["users"] to self.users var
self.valueArray = parseUSERS as! [AnyObject]
if self.valueArray.count > 0 {
let num_currentLoadedCardsArrayCap = (self.valueArray.count > MAX_BUFFER_SIZE) ? MAX_BUFFER_SIZE : self.valueArray.count
for (i,value) in self.valueArray.enumerated() {
let ava = self.valueArray[i]["ava"]
let id = self.valueArray[i]["id"]
let age = (NSString(format: "%@", self.valueArray[i]["age"] as! CVarArg))
let city = self.valueArray[i]["city"]
let state = self.valueArray[i]["state"]
self.age.append(age as AnyObject)
self.city.append(city as AnyObject)
self.state.append(state as AnyObject)
let url = NSURL(string: ava! as! String)! // convert path of str to url
let imageData = try? Data(contentsOf: url as URL)
let image = UIImage(data: imageData!)! // convert data of image via data imageData to UIImage
self.circleArray.append(image)
let reviewed = self.valueArray[i]["username"]
//let reviewed2 = reviewed
self.reviewed.append((reviewed as AnyObject) as! String)
//self.valueArray.append((reviewed as? String)! as AnyObject)
let shot = self.valueArray[i] as! NSDictionary
print("reviewed user", reviewed!)
let newCard = self.createDraggableViewWithData(at: i, value:shot)
//print("2nd new card attempt", newCard)
self.allCardsArray.append(newCard)
if i < num_currentLoadedCardsArrayCap {
self.currentLoadedCardsArray.append(newCard)
}
}
for (i,_) in self.currentLoadedCardsArray.enumerated() {
if i > 0 {
self.viewTinderBackGround.insertSubview(self.currentLoadedCardsArray[i], belowSubview: self.currentLoadedCardsArray[i - 1])
}
else {
self.viewTinderBackGround.addSubview(self.currentLoadedCardsArray[i])
}
self.currentIndex += 1
}
self.animateCardAfterSwiping()
self.perform(#selector(self.createDummyCard), with: nil, afterDelay: 1.0)
}
} catch {
// get main queue to communicate back to user
DispatchQueue.main.async(execute: {
let message = "\(error)"
//appDelegate.infoView(message: message, color: colorSmoothRed)
})
return
}
} else {
// get main queue to communicate back to user
DispatchQueue.main.async(execute: {
let message = error!.localizedDescription
//appDelegate.infoView(message: message, color: colorSmoothRed)
})
return
}
})
} .resume()
}
extension ShotsViewController : TinderCardDelegate{
func insertShot(_ rating: String, _ reviewed2: NSDictionary) {
// shortcuts to data to be passed to php file
let reviewer = user!["username"] as! String
print("reviewer", reviewer)
let reviewed2 = reviewed[index]
print("3rd print", reviewed2)
// url path to php file
let url = URL(string: "http://localhost/shotsCenter.php")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
// param to be passed to php file
let param = [
"user" : reviewer,
"revieweduser" : reviewed2,
"rating" : rating
] as [String : Any]
// body
let boundary = "Boundary-\(UUID().uuidString)"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
// ... body
request.httpBody = createBodyWithParams(param as? [String : String], boundary: boundary)
// launch session
URLSession.shared.dataTask(with: request) { data, response, error in
// get main queu to communicate back to user
DispatchQueue.main.async(execute: {
if error == nil {
do {
// json containes $returnArray from php
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
// declare new var to store json inf
guard let parseJSON = json else {
print("Error while parsing")
return
}
// get message from $returnArray["message"]
let message = parseJSON["message"]
// if there is some message - post is made
if message != nil {
}
} catch {
// get main queue to communicate back to user
DispatchQueue.main.async(execute: {
let message = "\(error)"
appDelegate.infoView(message: message, color: colorSmoothRed)
})
return
}
} else {
// get main queue to communicate back to user
DispatchQueue.main.async(execute: {
let message = error!.localizedDescription
appDelegate.infoView(message: message, color: colorSmoothRed)
})
return
}
})
}.resume()
}