{"action":"created","issue":{"url":"https://api.github.com/repos/daltoniam/Starscream/issues/130","labels_url":"https://api.github.com/repos/daltoniam/Starscream/issues/130/labels{/name}","comments_url":"https://api.github.com/repos/daltoniam/Starscream/issues/130/comments","events_url":"https://api.github.com/repos/daltoniam/Starscream/issues/130/events","html_url":"https://github.com/daltoniam/Starscream/issues/130","id":113588329,"number":130,"title":"self is nil on iPhone","user":{"login":"SamDecrock","id":550487,"avatar_url":"https://avatars.githubusercontent.com/u/550487?v=3","gravatar_id":"","url":"https://api.github.com/users/SamDecrock","html_url":"https://github.com/SamDecrock","followers_url":"https://api.github.com/users/SamDecrock/followers","following_url":"https://api.github.com/users/SamDecrock/following{/other_user}","gists_url":"https://api.github.com/users/SamDecrock/gists{/gist_id}","starred_url":"https://api.github.com/users/SamDecrock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamDecrock/subscriptions","organizations_url":"https://api.github.com/users/SamDecrock/orgs","repos_url":"https://api.github.com/users/SamDecrock/repos","events_url":"https://api.github.com/users/SamDecrock/events{/privacy}","received_events_url":"https://api.github.com/users/SamDecrock/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-27T13:53:56Z","updated_at":"2015-10-27T17:18:38Z","closed_at":null,"body":"Hi,\r\n\r\nI'm trying out Starscream 0.9.7 (Swift 1.2) for iOS using Cocoa Pods.\r\n\r\nWhen connecting right after initialising the websocket object, the ```self?``` inside the ```connect()```-function is ```nil``` and so ```createHTTPRequest()``` doesn't get called so no websocket connecting is made.\r\n\r\n```Swift\r\nvar socket: WebSocket!\r\n\r\noverride func viewDidLoad() {\r\n    super.viewDidLoad()\r\n    // Do any additional setup after loading the view, typically from a nib.\r\n    \r\n    socket = WebSocket(url: NSURL(scheme: \"ws\", host: \"10.100.11.50:3001\", path: \"/\")!)\r\n    socket.delegate = self\r\n    socket.connect()\r\n}\r\n```\r\n\r\nHowever, when connecting some time after the websocket object is created, ```self?``` is not ```nil``` and the socket connects. \r\n\r\n```Swift\r\nvar socket: WebSocket!\r\n\r\noverride func viewDidLoad() {\r\n    super.viewDidLoad()\r\n    // Do any additional setup after loading the view, typically from a nib.\r\n    \r\n    socket = WebSocket(url: NSURL(scheme: \"ws\", host: \"10.100.11.50:3001\", path: \"/\")!)\r\n    socket.delegate = self\r\n}\r\n\r\n@IBAction func buttonConnect_touchUp(sender: AnyObject) {\r\n    socket.connect()\r\n}\r\n```\r\n\r\nAlso, when adding a ```println(self)``` to the ```connect()```-function, the problem is solved:\r\n\r\n```Swift\r\npublic func connect() {\r\n    if isCreated {\r\n        return\r\n    }\r\n    dispatch_async(queue,{ [weak self] in\r\n        self?.didDisconnect = false\r\n        println(self)\r\n        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), { [weak self] in\r\n            self?.isCreated = true\r\n            self?.createHTTPRequest()\r\n            self?.isCreated = false\r\n        })\r\n    })\r\n}\r\n```\r\n\r\nCould this be another timing issue?\r\n\r\nGrtz,\r\nSam"},"comment":{"url":"https://api.github.com/repos/daltoniam/Starscream/issues/comments/151575225","html_url":"https://github.com/daltoniam/Starscream/issues/130#issuecomment-151575225","issue_url":"https://api.github.com/repos/daltoniam/Starscream/issues/130","id":151575225,"user":{"login":"daltoniam","id":905059,"avatar_url":"https://avatars.githubusercontent.com/u/905059?v=3","gravatar_id":"","url":"https://api.github.com/users/daltoniam","html_url":"https://github.com/daltoniam","followers_url":"https://api.github.com/users/daltoniam/followers","following_url":"https://api.github.com/users/daltoniam/following{/other_user}","gists_url":"https://api.github.com/users/daltoniam/gists{/gist_id}","starred_url":"https://api.github.com/users/daltoniam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daltoniam/subscriptions","organizations_url":"https://api.github.com/users/daltoniam/orgs","repos_url":"https://api.github.com/users/daltoniam/repos","events_url":"https://api.github.com/users/daltoniam/events{/privacy}","received_events_url":"https://api.github.com/users/daltoniam/received_events","type":"User","site_admin":false},"created_at":"2015-10-27T17:18:38Z","updated_at":"2015-10-27T17:18:38Z","body":"Yeah I think that might have been an issue. Looking at the latest code we change the connect method:\r\nhttps://github.com/daltoniam/Starscream/blob/master/WebSocket.swift#L127\r\n\r\nMight want to try changing it to that and see if that resolves the issue. "}}