Swift 2 - Variable initiation failed (lldb) - ios

I'm just starting developing apps with Swift 2.0, and as I'm working having problem with initiating a variable with the value of a text field in my app.
this is the function I'm having problems with. It's called when a button under the text field is pressed as submit.
#IBAction func checkName(sender: AnyObject) {
guard let name : String = nameField.text else { print("Name not valid.");return}
let checker = NameChecker()
let result = checker.nameChecker(name)
print(result)
}
this only thing this code returns on the XCode shell is "lldb". I also tried to use the debugger to figure out where I was messing up but unfortunately I found out that was harder than expected and I wasn't able to.
If you have any idea why my code is only returning "lldb" I would really appreciate is you could let me know since I've been experiencing this error quite often lately.

Related

UIImage not being read properly after entering foreground

I am in a real rough situation trying to squish this bug.
In a perfect world, I can press a "success" button, it plays a sound and vibrates, and changes the image in a UIImageView. This works perfectly until I press the home button and reopen the app. This glitch ALWAYS occurs.
Here is the relevant code:
#IBAction func Success(_ sender: Any) {
var boxNum = 1
generator.impactOccurred()
if "" == defaults.value(forKey: "frequency") as? String{
//One of 2 frequencies. It doesn't make a difference, however because the glitch always happens.
playVictorySound()
let formatter = DateFormatter()
for box in Boxes{
if box.image == UIImage(named:"blank.png"){
if "" == defaults.value(forKey: mode) as? String{
formatter.dateFormat = "dd.MM.yyyy"
let activeDate = Date()
defaults.set(Date(), forKey: "dateLast")
print(activeDate)
}
box.image = UIImage(named:"Arm.png")
defaults.set("Active", forKey: "boxState" + String(boxNum))
print("Active set for" + " boxState" + String(boxNum))
if "" == defaults.value(forKey: "mode") as? String{
successButton.isHidden = true
failButton.isHidden = true
}
break
}
else{
boxNum = boxNum + 1
print ("Added 1 to" + String(boxNum))
}
}
}
NOTE: This section has the user defaults that are set during the button press.
When the app is re-opened, the success button plays a sound (which is desired), and vibrates the phone (also desired), but the images do not update. In fact, the console prints a series of the else case.
Added 1 to38
Added 1 to39
Added 1 to40
Etc etc.
When any other modes or frequencies are set, the glitch also occurs. I am focused on fixing this case because I think I will be able to fix the others as well.
Is there some underlying reason causing this? I believe it may be because either something isn't being kept in memory, but I cannot figure out why. Thank you very much.
EDIT: Ok, I set the "blank" image to a selfie, and the app loads up "blank.png" for every square. There seems to be something wrong with another part of the code above.
I added print statements to help a bit and the if statement is the part that is failing, however, the ImageViews all have blank.png set as their image.
I fixed my issue using a workaround. I stopped checking the content of the UIImageView (Which for some reason didn't work), and instead used UserDefaults to see what the image should be.
I set a value in UserDefaults for all the possible images, and then check what the value of the default is.

Firebase not taking all arguments

My code goes as followed.
Once I get to the part where I am writing to the database it seems to skip over ContestName. Then it will record the contestdescription and user to the database. If I put contestDescription first before contestName then the contestDescription is missed but the name gets stored. Really funky bug. Any help would be appreciated.
NOTE: I tried a sleep but that didn't help at all.
#IBAction func SubmitContest(_ sender: Any) {
//Convert to text
let contesttitle = ContestName.text;
let contestdescript = ContestDescription.text;
//Some Firebase Stuff
let userID = Auth.auth().currentUser?.uid
let contestRef = ref.child("craftType").child("Custom")
let thisContest = contestRef.childByAutoId()
//Store to firebase
//Whatever one is first is not making it to firebase database
thisContest.setValue(["ContestName": contesttitle])
thisContest.setValue(["ContestDescription": contestdescript])
thisContest.child("User").setValue(userID)
}
Calling setValue on a location replaces all existing data at that location. So in this snippet:
thisContest.setValue(["ContestName": contesttitle])
thisContest.setValue(["ContestDescription": contestdescript])
The second line is replacing whatever the first line writes.
You should either combine the two:
thisContest.setValue(["ContestName": contesttitle, "ContestDescription": contestdescript])
Or use updateChildValues (which doesn't replace the entire data at the location, but only at the properties you specify):
thisContest.updateChildValues(["ContestName": contesttitle])
thisContest.updateChildValues(["ContestDescription": contestdescript])

"CoreData: error: NULL _cd_rawData but the object is not being turned into a fault"

This is a part if code when error happens:
class func randomWord() -> TBWord {
let randomIndex = Int(arc4random_uniform(UInt32(TBAppSettings.wordsForCurrentGame.count)))
let word = TBAppSettings.wordsForCurrentGame[randomIndex]
TBAppSettings.wordsForCurrentGame.removeAtIndex(randomIndex)
MagicalRecord.saveWithBlock { context in
let word = TBWord.findWordWithIdentifier(word.identifier, inContext: context) //here error happens
word?.used = true
}
return word
}
How can I workaround this? I know about other questions about this problem, but they are not enough for me.
(Besides the fact that MagicalRecord is a big misunderstanding of how to use Core Data properly...)
Have you tried to run you code with -com.apple.CoreData.ConcurrencyDebug 1 as a launch argument? This smells like a threading problem.

exc-bad-instruction code=i386_invop

I'm getting this error in latest version of xcode using swift 2
on line
let s = linkTxt.text
Text in linkTxt appears by button "pasteFromClipBoard"
let s = linkTxt.text
let u = NSURL(string: s!)
let file = u?.lastPathComponent
What is the reason of it and how to fix it?
Update:
the problem appears in function saveData() which calls when file downloading is finished. It calls from NSURLSessionDataTask function. More interesting, that in start-downloading-button there are the same lines where filename is generating and there is no such error on it. I fixed these issues by declaring variables, writing text's values into them and use these variables in saveData() except textObject.text; I had to delete lines with NSUserDefaults from saveData() too because I got the same error. Did understand nothing >_<
Update 2:
It's really a bug. I've deleted this line and wrote again - problem fixed
linkTxt.txt is returning nil and NSURL(string: s!) will try to forcefully unwrap it.
let s = linkTxt.text
if let s = linkTxt.txt {
let u = NSURL(string: s!)
let file = u?.lastPathComponent
}

EXC_BREAKPOINT on launch after using NSUserDefaults on iOS 8 Swift on iPhone 5s, not simulator

Just after implementing a method for saving a users email and password from login into NSUserDefaults. My app crashes when running on iPhone 5s, but not in simulator (works as supposed).
Error message is:
dyld: Symbol not found: __TWPVSs26AutoreleasingUnsafePointerSs8_Pointer
Referenced from: /private/var/mobile/Containers/Bundle/Application/76A645B8-3428-452F-AEA4-60BAF6C28819/AppName.app/AppName
Expected in: /private/var/mobile/Containers/Bundle/Application/76A645B8-3428-452F-AEA4-60BAF6C28819/AppName.app/Frameworks/libswift_stdlib_core.dylib
in /private/var/mobile/Containers/Bundle/Application/76A645B8-3428-452F-AEA4-60BAF6C28819/AppName.app/AppName
My NSUserDefaults code is this (don't think the rest matters):
let loggedIn = "yes"
let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setObject(email, forKey:"Email")
userDefaults.setObject(pw, forKey:"Password")
userDefaults.setObject(loggedIn, forKey: "LoggedIn")
userDefaults.synchronize()
This is set after user has entered email and password and the server has validated these and returned "ok".
In prepareForSegue I have this code:
let navigationController = segue.destinationViewController as UINavigationController
let vc = navigationController.viewControllers[0] as LoggedInViewController
// Gets email from saved data
let userDefaults = NSUserDefaults.standardUserDefaults()
let sendEmail: String = userDefaults.stringForKey("Email")
userDefaults.synchronize()
vc.email = sendEmail
Update:
I have gone through the crash logs and noticed this:
I dont really know how to read it but I noticed that exception code 0x0000000196442124 is at the bottom of my included image.
_dispatch_mach_msg_send + 1624
What does that mean? Does it help?
I have also marked all methods and stuff that has with NSUserDefaults (as seen above) as comments to see if they caused the problem. But the app crashes anyway..
Thanks in advance!
The error message says something about autoreleasing memory.
Do you have any ...Release() function calls within your swift code?
If so, comment them out and try again.
let sendEmail: String = userDefaults.stringForKey("Email")
for me swift is confused by lines like these and fails to correctly infer the type.
It performs ..... I don't what but it can't really get from anyobject! to string correctly
it crashes when it tries to work with sendEmail
see:
Get from AnyObject(NSString) to String

Resources