EXC错误指示

时间:2016-04-17 06:18:56

标签: swift

我正在使用Twilio作为我正在处理的聊天应用程序,但在尝试登录时我一直收到此错误指令错误。我不确定这是什么,因为它适用于教程和YouTube视频。

这是我的代码。

class ChannelManager: NSObject {
static let sharedManager = ChannelManager()

static let defaultChannelUniqueName = "general"
static let defaultChannelName = "General Channel"

weak var delegate:TwilioIPMessagingClientDelegate?

var channelsList:TWMChannels?
var channels:NSMutableOrderedSet?
var generalChannel:TWMChannel!

override init() {
super.init()
IPMessagingManager.sharedManager().client?.delegate = self
}

// MARK: - General channel

 func joinGeneralChatRoomWithCompletion(completion: Bool -> Void) {
populateChannelsWithCompletion { succeeded in
  let uniqueName = ChannelManager.defaultChannelUniqueName
  if let channelsList = self.channelsList {
    self.generalChannel = channelsList.channelWithUniqueName(uniqueName)
  }

  if self.generalChannel != nil {
    self.joinGeneralChatRoomWithUniqueName(nil, completion: completion)
    return
  }

  self.createGeneralChatRoomWithCompletion { succeeded in
    if (succeeded) {
      self.joinGeneralChatRoomWithUniqueName(uniqueName, completion: completion)
      return
    }

    completion(false)
  }
}
 }

  func joinGeneralChatRoomWithUniqueName(name: String?, completion: Bool -> Void) {
generalChannel.joinWithCompletion { result in
  if (result == .Success && name != nil) {
    self.setGeneralChatRoomUniqueNameWithCompletion(completion)
    return
  }
  completion(result == .Success)
}
 }

  func createGeneralChatRoomWithCompletion(completion: Bool -> Void) {
let channelName = ChannelManager.defaultChannelName
channelsList!.createChannelWithFriendlyName(channelName, type: .Public)   { result, channel in
  if (result == .Success) {
    self.generalChannel = channel
  }
  completion(result == .Success)
}
  }

  func setGeneralChatRoomUniqueNameWithCompletion(completion:Bool -> Void) {
generalChannel.setUniqueName(ChannelManager.defaultChannelUniqueName) { result in
  completion(result == .Success)
}
  }

  // MARK: - Populate channels

  func populateChannelsWithCompletion(completion: Bool -> Void) {
channels = nil

loadChannelListWithCompletion { succeeded, channelList in
  if (!succeeded) {
    dispatch_async(dispatch_get_main_queue(), {
      self.channelsList = nil
      self.channels = nil
      completion(false)
    })
    return
  }

  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
    channelList!.loadChannelsWithCompletion { result in
      if (result == .Success) {
        self.channels = NSMutableOrderedSet()
        self.channels!.addObjectsFromArray(channelList!.allObjects())
        self.sortChannels()
      }
      dispatch_async(dispatch_get_main_queue()) {
        completion(result == .Success)
      }
    }
  }
}
  }

  func loadChannelListWithCompletion(completion: (Bool, TWMChannels?) -> Void) {
self.channelsList = nil

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
  IPMessagingManager.sharedManager().client!.channelsListWithCompletion { result, channelsList in
    if (result == .Success) {
      self.channelsList = channelsList
    }
    dispatch_async(dispatch_get_main_queue(), {
      completion(result == .Success, self.channelsList)
    })
  }
}
 }

 func sortChannels() {
let sortSelector = Selector("localizedCaseInsensitiveCompare:")
let descriptor = NSSortDescriptor(key: "friendlyName", ascending: true, selector: sortSelector)
channels!.sortUsingDescriptors([descriptor])
}

// MARK: - Create channel

 func createChannelWithName(name: String, completion: (Bool, TWMChannel?) -> Void) {
if (name == ChannelManager.defaultChannelName) {
  completion(false, nil)
  return
}

if (channelsList == nil)
{
  loadChannelListWithCompletion { succeeded, channelsList in
    if (succeeded) {
      self.createChannelWithName(name, completion: completion)
      return
    }
    completion(succeeded, nil)
  }
  return
}

self.channelsList?.createChannelWithFriendlyName(name, type: .Public) { result, channel in
  completion(result == .Success, channel)
}
 }
 }

// MARK: - TwilioIPMessagingClientDelegate
extension ChannelManager : TwilioIPMessagingClientDelegate {
func ipMessagingClient(client: TwilioIPMessagingClient!, channelAdded    channel: TWMChannel!) {
dispatch_async(dispatch_get_main_queue(), {
  if self.channels != nil {
    self.channels!.addObject(channel)
    self.sortChannels()
    self.delegate?.ipMessagingClient?(client, channelAdded: channel)
  }
})
 }

 func ipMessagingClient(client: TwilioIPMessagingClient!, channelChanged channel: TWMChannel!) {
dispatch_async(dispatch_get_main_queue(), {
  if self.channels != nil {
    self.delegate?.ipMessagingClient?(client, channelChanged: channel)
  }
})
}

 func ipMessagingClient(client: TwilioIPMessagingClient!, channelDeleted channel: TWMChannel!) {
dispatch_async(dispatch_get_main_queue(), {
  if self.channels != nil {
    self.channels?.removeObject(channel)
    self.delegate?.ipMessagingClient?(client, channelDeleted: channel)
  }
})
}
}

以下是包含错误的代码行。

channelsList!.createChannelWithFriendlyName(channelName, type: .Public) { result, channel in

谢谢,吕克

0 个答案:

没有答案