swift2

Xcode: how to fix Thread 5: EXC_BREAKPOINT (code=1, subcode=0x10025c76c)

吃可爱长大的小学妹 提交于 2019-12-29 09:12:35
问题 when I click the btnLogin in the iPhone the xCode was displayed the error: Thread 5: EXC_BREAKPOINT (code=1, subcode=0x10025c76c) this is my code @IBOutlet weak var abc: UILabel! ... @IBAction func btnLogin(sender: UIButton) { var jsonResult = AnyObject?() let urlAsString = "lifewinner2015.dlinkddns.com/SERVER/user?function=login&username=Shing&password=123456789" let url = NSURL(string: urlAsString) let urlSession = NSURLSession.sharedSession() let jsonQuery = urlSession.dataTaskWithURL(url!

Swfit 2 “Extra argument 'error' in call”

你。 提交于 2019-12-29 08:25:10
问题 I've been having a problem understanding what xcode wants from me when it gives me the "Extra argument 'error' in call" it keeps pointing to if let feed = NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers, error: nil) as? NSDictionary, I read somewhere that in swift 2 I should add do { but everytime I add it I just keep breaking more stuff. What's the correct syntax in swift 2? This is the code: override func viewDidLoad() { super.viewDidLoad() let request =

sorted function in Swift 2

限于喜欢 提交于 2019-12-29 07:55:48
问题 I'm sorting an Array like this: var users = ["John", "Matt", "Mary", "Dani", "Steve"] func back (s1:String, s2:String) -> Bool { return s1 > s2 } sorted(users, back) But I'm getting this error 'sorted' is unavailable: call the 'sort()' method on the collection What should be the correct way to use the sort() method here? 回答1: Follow what the error message is telling you, and call sort on the collection: users.sort(back) Note that in Swift 2 , sorted is now sort and the old sort is now

Can I bind different associated values in a Swift enum to the same var?

谁都会走 提交于 2019-12-29 07:18:29
问题 I made a little "Angle" enum so that I could program with different interchangeable angular formats: enum Angle { case Radians(CGFloat) case Degrees(CGFloat) case Rotations(CGFloat) } I find that there's some redundant boilerplate code with this approach though. For example, I wanted to add a computed var that just returned the raw underlying associated float: var raw:CGFloat { switch self { case let .Radians(value): return value case let .Degrees(value): return value case let .Rotations

Can I bind different associated values in a Swift enum to the same var?

只谈情不闲聊 提交于 2019-12-29 07:18:09
问题 I made a little "Angle" enum so that I could program with different interchangeable angular formats: enum Angle { case Radians(CGFloat) case Degrees(CGFloat) case Rotations(CGFloat) } I find that there's some redundant boilerplate code with this approach though. For example, I wanted to add a computed var that just returned the raw underlying associated float: var raw:CGFloat { switch self { case let .Radians(value): return value case let .Degrees(value): return value case let .Rotations

'++' is deprecated: it will be removed in Swift 3 [duplicate]

那年仲夏 提交于 2019-12-29 04:33:16
问题 This question already has answers here : The “++” and “--” operators have been deprecated Xcode 7.3 (10 answers) Closed 3 years ago . After update to Xcode 7.3 , there are bunch of warnings showing in my project. '++' is deprecated: it will be removed in Swift 3 Any idea to fix this warning ? Any reasons why the ++ and -- will be deprecated in the future ? 回答1: Since Swift 2.2, you should use += 1 or -= 1 instead. And after looking up Swift's evolution, there are some reasons for removing

How can I build a URL with query parameters containing multiple values for the same key in Swift?

纵然是瞬间 提交于 2019-12-29 04:27:08
问题 I am using AFNetworking in my iOS app and for all the GET requests it makes, I build the url from a base URL and than add parameters using NSDictionary Key-Value pairs. The problem is that I need same key for different values. Here is an example of what I need the finally URL to look like - http://example.com/.....&id=21212&id=21212&id=33232 It's not possible in NSDictionary to have different values in same keys. So I tried NSSet but did not work. let productIDSet: Set = [prodIDArray] let

How to split a string into substrings of equal length

白昼怎懂夜的黑 提交于 2019-12-28 06:31:26
问题 So split("There are fourty-eight characters in this string", 20) should return ["There are fourty-eig", "ht characters in thi","s string"] If I make currentIndex = string.startIndex and then try to advance() it further than a string.endIndex, I get "fatal error: can not increment endIndex" before I check if my currentIndex < string.endIndex so the code below doesn't work var string = "12345" var currentIndex = string.startIndex currentIndex = advance(currentIndex, 6) if currentIndex > string

How to split a string into substrings of equal length

99封情书 提交于 2019-12-28 06:31:08
问题 So split("There are fourty-eight characters in this string", 20) should return ["There are fourty-eig", "ht characters in thi","s string"] If I make currentIndex = string.startIndex and then try to advance() it further than a string.endIndex, I get "fatal error: can not increment endIndex" before I check if my currentIndex < string.endIndex so the code below doesn't work var string = "12345" var currentIndex = string.startIndex currentIndex = advance(currentIndex, 6) if currentIndex > string

alamofire.error Code=-6006 "JSON could not be serialized

心不动则不痛 提交于 2019-12-28 04:18:08
问题 Been working on this for a bit with no success. I have a function that goes to a UIButton solely to perform alamofire calls to my rails api which uses all JSON. I'm using Swift 2, Alamofire 3, XCode 7 & Rails 4 for my api which is deployed to Heroku I keep getting this error when I fire off the function : alamofire.error Code=-6006 "JSON could not be serialized. Input data was nil or zero length. Here is my code : @IBAction func Save(sender: AnyObject) { let postsEndpoint: String = "https:/