Crashed: com.apple.main-thread EXC_BREAKPOINT 0x0000000100c5009c keyboard_arrow_up - ios

I am new iOS development, I got this error from firebase crash analytics. Can anyone help me why this errors occurs?
Crashed: com.apple.main-thread
0 People Time Tracking 0x100c5009c closure #1 in closure #1 in SelectJobScreen.getPreviousStatus() (SelectJobScreen.swift:798)
1 People Time Tracking 0x100cb2648 thunk for #escaping #callee_guaranteed () -> () (<compiler-generated>)
2 libdispatch.dylib 0x1e6993a38 _dispatch_call_block_and_release + 24
3 libdispatch.dylib 0x1e69947d4 _dispatch_client_callout + 16
4 libdispatch.dylib 0x1e6942004 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068
5 CoreFoundation 0x1e6ee4ec0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
6 CoreFoundation 0x1e6edfdf8 __CFRunLoopRun + 1924
7 CoreFoundation 0x1e6edf354 CFRunLoopRunSpecific + 436
8 GraphicsServices 0x1e90df79c GSEventRunModal + 104
9 UIKitCore 0x212cc5b68 UIApplicationMain + 212
10 People Time Tracking 0x100c1afcc main (TodoItem.swift:17)
11 libdyld.dylib 0x1e69a58e0 start + 4
I've tried figuring out what could cause this crash for a few days now, and haven't been able to reproduce it. I don't see any implicit unwraps or optionals here, but sessionId is a non-optional value in the session object if that matters.
I am using swift 4.1, and the crashes occur on on iOS devices running all the different flavours of iOS 10, 11, and 12. The app does support some builds of iOS 9, but none have been reported (although that may be irrelevant because the iOS 9 user base for the app is extremely small)
In Error log it's showing this function getPreviousStatus()
func getPreviousStatus() {
let connect = JsonManger()
let app = UIApplication.shared.delegate as! AppDelegate
let user:User = app.dataManager.gUser
if Reachability.isConnectedToNetwork() {
self.showHUD( msg: "Loading...." )
connect.getLogDetails(baseUrl: user.ClientWeb, email: user.EmailID, password: user.Password, brugerId: user.BrugerID, success: { (res) in
var indud = false
if ( res.object(forKey: "indud") != nil ){
indud = res.object(forKey: "indud") as! Bool
}
if indud {
var isTodo = false
if res.object(forKey: "isToDo") != nil {
isTodo = res.object(forKey: "isToDo") as! Bool
}
if isTodo {
var str = res.object(forKey: "JobId") as! String
let index = str.index(str.startIndex, offsetBy: 1)
str = str.substring(from: index)
let prjId = Int(str)!
let project = app.dataManager.gProject.getProject(id: prjId)
let todoId = res.object(forKey: "TodoId") as! String
let todo = app.dataManager.gTodo.getTodo(id: Int(todoId)!)
self.project = project
self.todoItem = todo
app.dataManager.isCheckedin = true
self.des = res.object(forKey: "JobDescription") as? String
let startTime = res.object(forKey: "Dato2") as! String
DispatchQueue.main.async {
let ud = UserDefaults.standard
ud.set(true, forKey: "isCheckedIn")
ud.set( 1, forKey:"type")
ud.set( self.project.ID!, forKey: "projectId" )
ud.set( self.todoItem.ID! , forKey: "todoId" )
// print(" todo data is : \(self.todoItem.ID!)")
ud.set( self.des, forKey: "des")
ud.set( startTime,forKey: "startTime")
ud.set( startTime, forKey: "checkInTime" )
ud.synchronize()
self.hideHUD()
self.performSegue(withIdentifier: "goStartTodoFromSelect", sender: nil )
}
} else {
var jobId = res.object(forKey: "JobId") as! String
jobId = jobId.replacingOccurrences(of: "P", with: "")
self.des = res.object(forKey: "JobDescription") as? String
let jobCode = app.dataManager.gJobCode.getJobCode(id: Int(jobId)! )
self.jobCodeItem = jobCode
// let chekinTime = res.object(forKey: "Dato2") as! String
let startTime = "2019-05-15T19:45:00"
DispatchQueue.main.async {
app.dataManager.isCheckedin = true
let ud = UserDefaults.standard
ud.set(true, forKey: "isCheckedIn")
ud.set( 0, forKey:"type")
ud.set( jobId, forKey: "jobId" )
ud.set( startTime,forKey: "startTime")
ud.set( startTime, forKey: "checkInTime" )
if res.object(forKey: "JobDescription") != nil {
self.des = res.object(forKey: "JobDescription") as? String
ud.set( self.des, forKey: "des")
}
ud.synchronize()
DispatchQueue.main.async {
self.hideHUD()
self.performSegue(withIdentifier: "goStartJob", sender: nil )
}
}
}
} else {
DispatchQueue.main.async {
self.hideHUD()
// self.popToRoot()
for controller in self.navigationController!.viewControllers as Array {
if controller.isKind(of: SelectJobScreen.self) {
self.navigationController!.popToViewController(controller, animated: true)
break
}
}
}
}
}) { (error) in
DispatchQueue.main.async {
self.hideHUD()
// self.popToRoot()
for controller in self.navigationController!.viewControllers as Array {
if controller.isKind(of: SelectJobScreen.self) {
self.navigationController!.popToViewController(controller, animated: true)
break
}
}
}
}
} else {
print("Record Not Found")
}
}

Inside of that getPreviousStatus() functions getting null values , check it once using debugging
DispatchQueue.main.async {
# mainly in this thread getting error check it once
let ud = UserDefaults.standard
ud.set(true, forKey: "isCheckedIn")
ud.set( 1, forKey:"type")
ud.set( self.project.ID!, forKey: "projectId" )
ud.set( self.todoItem.ID! , forKey: "todoId" )
// print(" todo data is : \(self.todoItem.ID!)")
ud.set( self.des, forKey: "des")
ud.set( startTime,forKey: "startTime")
ud.set( startTime, forKey: "checkInTime" )
ud.synchronize()
self.hideHUD()
self.performSegue(withIdentifier: "goStartTodoFromSelect", sender: nil )
}

Related

iOS App Store app crashes during login (not in development)

So this may be because UserDefaults are getting reset after a period of time, maybe because I update the OS frequently, but a released version of my iOS app after a period of time will crash on my login screen, probably where I check for saved credentials (in UserDefaults). Reinstalling the app fixes the issue. Console returns a lot of :
Unsupported use of UIKit view-customization API off the main thread. -setAlignsToKeyboard: sent to <_UIAlertControllerView: 0x125b2d070; frame = (0 0; 414 896); layer = <CALayer: 0x283f652e0>>
And my system logs show an error on this thread:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 4
Application Specific Information:
abort() called
Thread 4 name: Dispatch queue: com.apple.NSURLSession-delegate Thread
4 Crashed: 0 libsystem_kernel.dylib 0x00000001bfb4e414 0x1bfb26000 +
164884 1 libsystem_pthread.dylib 0x00000001dd6a8b50 0x1dd6a6000 +
11088 2 libsystem_c.dylib 0x000000019b027b74 0x19afb1000 + 486260 3
libc++abi.dylib 0x00000001a6d1acf8 0x1a6d07000 + 81144 4
libc++abi.dylib 0x00000001a6d0be4c 0x1a6d07000 + 20044 5
libobjc.A.dylib 0x00000001a6c14f64 0x1a6c0e000 + 28516 6
libc++abi.dylib 0x00000001a6d1a0e0 0x1a6d07000 + 78048 7
libc++abi.dylib 0x00000001a6d1a06c 0x1a6d07000 + 77932 8
libdispatch.dylib 0x00000001917eddc4 0x1917ea000 + 15812 9
libdispatch.dylib 0x00000001917f510c 0x1917ea000 + 45324 10
libdispatch.dylib 0x00000001917f5c90 0x1917ea000 + 48272 11
libdispatch.dylib 0x00000001917ffd78 0x1917ea000 + 89464 12
libsystem_pthread.dylib 0x00000001dd6a9814 0x1dd6a6000 + 14356 13
libsystem_pthread.dylib 0x00000001dd6b076c 0x1dd6a6000 + 42860
Here is some code that I use to check saved credentials. In the backend API I cannot see any login attempts. If it helps, I can see this viewcontroller for a split second right before it crashes. Not sure if that rules out viewdidload.
override func viewDidLoad() {
super.viewDidLoad()
addLoadingSpinner()
bLogIn.titleLabel?.font = UIFont.setToVoiceLight()
self.tfCustomerID.delegate = self
self.tfUsername.delegate = self
self.tfPassword.delegate = self
tfUsername.keyboardType = .default
tfPassword.textContentType = .password
setupUI()
if UserDefaults.standard.string(forKey: UserDefaultsKeys.session) != nil
&& UserDefaults.standard.string(forKey: UserDefaultsKeys.savedCred) == "True" {
login_session = UserDefaults.standard.string(forKey: UserDefaultsKeys.session)!
check_session()
}
else if UserDefaults.standard.string(forKey: UserDefaultsKeys.savedCred) == "True" &&
UserDefaults.standard.string(forKey: UserDefaultsKeys.usesBiometrics) == "True" {
promptTouchOrFaceID()
}
removeLoadingSpinner()
}
override func viewWillAppear(_ animated: Bool) {
AppDelegate.AppUtility.lockOrientation(UIInterfaceOrientationMask.portrait, andRotateTo:
UIInterfaceOrientation.portrait)
cbSave.isChecked = UserDefaults.standard.string(forKey: UserDefaultsKeys.savedCred) == "True"
addObservers()
}
func check_session() {
UserDefaults.standard.set(login_session, forKey: "session")
UserInfo.access_token = UserDefaults.standard.string(forKey: "session")!
var request = URLRequest(url: NSURL(string: checksession_url)! as URL)
request.httpMethod = .GET
request.addValues(...)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode == 200 {
//VERIFIED THAT NEVER GETTING TO API
DispatchQueue.main.async {
...
}
} else {
self.promptTouchOrFaceID()
UserDefaults.standard.set(nil, forKey: UserDefaultsKeys.session)
}
}
task.resume()
}
Here is my code for biometrics prompt:
func promptTouchOrFaceID() {
//create context for touch auth
let authenticationContext = LAContext()
var error: NSError?
authenticationContext.localizedFallbackTitle = ""
let biometricType = authenticationContext.biometricType
//check if the device has a fingerprint sensor, exit if not
guard authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
error: &error) else {
let title = "Error"
var message = ""
switch biometricType {
case .faceID:
message = "This device does not have a FaceID sensor or the sensor is not enabled."
case .touchID:
message = "This device does not have a TouchID sensor or the sensor is not enabled."
case .none:
message = "This device does not have any sensors to use TouchID or FaceID"
}
AlertService.showAlert(on: self, title: title, message: message)
UserDefaults.standard.set("False", forKey: UserDefaultsKeys.usesBiometrics)
removeLoadingSpinner()
return
}
authenticationContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
localizedReason: "Please use your fingerprint to authenticate.",
reply: { [unowned self] (success, error) -> Void in
if (success) {
//fingerprint recognized, set this possible and go to view controller
OperationQueue.main.addOperation({ () -> Void in
self.fillInUserDetails()
self.login_now(
username:self.tfUsername.text!,
password: self.userDefaults.string(forKey: UserDefaultsKeys.password)!,
customer: self.tfCustomerID.text!)
})
}
})
}
Just a wild shot, but do you have NSFaceIDUsageDescription key in your plist file. I remember having a problem like this a few months back.

Thread 0 crashed with ARM Thread State (64-bit)

I submited my app to app store, they said its crash when app launch. But for my device adn in simulator its working fine. Not able to find whats the issues here.
I attached the binary image with crash file what apple gave me.please let me know any 1 able to get the issue.
Here is that crash file
Thanks
the crash showed here :
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 WCi 0x0000000100df0454 specialized closure #1 in MainScreenViewController.getAdressName(coords:) + 509012 (MainScreenViewController.swift:668)
1 WCi 0x0000000100e01ed4 partial apply for closure #1 in MainScreenViewController.getAdressName(coords:) + 581332 (MainScreenViewController.swift:0)
2 WCi 0x0000000100de0288 _T0SaySo11CLPlacemarkCGSgs5Error_pSgIegxx_So7NSArrayCSgSo7NSErrorCSgIeyByy_TR + 443016 (MainScreenViewController.swift:0)
3 libdispatch.dylib 0x00000001d96596c8 0x1d95f9000 + 394952
4 libdispatch.dylib 0x00000001d965a484 0x1d95f9000 + 398468
5 libdispatch.dylib 0x00000001d96069a4 0x1d95f9000 + 55716
6 CoreFoundation 0x00000001d9bb0df4 0x1d9b05000 + 703988
7 CoreFoundation 0x00000001d9babcbc 0x1d9b05000 + 683196
8 CoreFoundation 0x00000001d9bab1f0 0x1d9b05000 + 680432
9 GraphicsServices 0x00000001dbe24584 0x1dbe19000 + 46468
10 UIKitCore 0x0000000206b38c00 0x206250000 + 9341952
11 WCi 0x0000000100dbeba4 main + 306084 (AppDelegate.swift:23)
12 libdyld.dylib 0x00000001d966abb4 0x1d966a000 + 2996
so in my MainScreenViewController.swift
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if firstload == false {
firstload = true
firstTimeLoads = true
currentlocation = locations.last!
let cityCoords = CLLocation(latitude: currentlocation.coordinate.latitude, longitude: currentlocation.coordinate.longitude)
let addresss = getAdressName(coords: cityCoords)
self.userlat = "\(currentlocation.coordinate.latitude)"
self.userlong = "\(currentlocation.coordinate.longitude)"
self.userDevice = "iOS"
self.userName = Uname ?? "NA"
self.userId = UId ?? "NA"
self.userTime = time
let camera = GMSCameraPosition.init(target: currentlocation.coordinate, zoom: 11, bearing: 0, viewingAngle: 0)
passloc = String(format: "%f,%f", currentlocation.coordinate.latitude,currentlocation.coordinate.longitude)
if let locationData = passloc {
self.movelocation = currentlocation
UserDefaults.standard.set(locationData, forKey: "storemyloc")
UserDefaults.standard.synchronize()
viewmap.animate(to: camera)
self.getAddressFromLatLon(location: currentlocation)
print("my address")
print(currentlocation)
print("LOG: LOCATION 1 \(searchlocation)")
if CLLocationCoordinate2DIsValid(self.searchlocation.coordinate) {
self.movelocation = self.searchlocation
} else {
self.runlink()
}
}
}
}
func getAdressName(coords: CLLocation) {
CLGeocoder().reverseGeocodeLocation(coords) { (placemark, error) in
if error != nil {
print("Hay un error")
} else {
let place = placemark! as [CLPlacemark]
if place.count > 0 {
let place = placemark![0]
var adressString : String = ""
if place.locality != nil {
adressString = adressString + place.name! + " - "
}
if place.thoroughfare != nil {
adressString = adressString + place.subLocality! + ", "
}
if place.locality != nil {
adressString = adressString + place.subAdministrativeArea! + " - "
}
if place.country != nil {
adressString = adressString + place.country!
}
self.Userdic.setValue(adressString, forKey: "useraddress")
self.userAdd = adressString
}
}
}
}
whats might be the issues here for that crash ? Cordinates - lat,long is not passed or issues is with func getAdressName(coords: CLLocation)
Replace your getAdressName with below code.
func getAdressName(coords: CLLocation) {
CLGeocoder().reverseGeocodeLocation(coords) { (placemark, error) in
if error != nil {
print("Hay un error")
} else {
let place = placemark! as [CLPlacemark]
if place.count > 0 {
let place = placemark![0]
var adressString : String = ""
if place.name != nil {
adressString = adressString + place.name! + " - "
}
if place.subLocality != nil {
adressString = adressString + place.subLocality! + ", "
}
if place.subAdministrativeArea != nil {
adressString = adressString + place.subAdministrativeArea! + " - "
}
if place.country != nil {
adressString = adressString + place.country!
}
self.Userdic.setValue(adressString, forKey: "useraddress")
self.userAdd = adressString
}
}
}
}
You checking the nil of locality but inside getting the value of place.subAdministrativeArea! which might in nil case.

Firebase: Runing transaction every time I loop through an Array

I'm trying to loop through Array and run transaction to upload each item on Firebase, but am not sure that what i want to do is possible.
The idea is: I have an Array of problems ["problemType1", "problemType2", ... "problemType10"] and I give the user n time to solve it. At the end, I put the solved problems in Array and upload them on Firebase. If the problem exists in the DB, just to update his value.
This way, I want to track what type of problems the player use to resolves easier. At the moment, the code I wrote uploads only one problem. What am I doing wrong?
func uploadTheResolvedProblemsToDB(problems: [String], uid: String) {
let refDB = FIRDatabase.database().reference().child("users").child(uid).child("problems")
for problem in problems {
refDB.runTransactionBlock({ (currentData:FIRMutableData) -> FIRTransactionResult in
var dataToUpdate = currentData.value as? [String : Any]
if dataToUpdate?[problem] == nil {
dataToUpdate = [problem: 0]
var theProblem = dataToUpdate?[problem] as? Int ?? 0
theProblem += 1
dataToUpdate?[problem] = 1
currentData.value = dataToUpdate
return FIRTransactionResult.success(withValue: currentData)
}
else
{
var theProblem = dataToUpdate?[problem] as? Int ?? 0
theProblem += 1
dataToUpdate?[problem] = theProblem
currentData.value = dataToUpdate
return FIRTransactionResult.success(withValue: currentData)
}
}) {(error,commited,snapshot) in
if let error = error {
print("errorrrrr", error.localizedDescription)
}
}
}
}
My Database structure is:
users
I_uid
I_problems
I_problem1: 1
problem2: 1
problem3: 1
Where problems is the child. problem1, problem2, problem3 are the values and 1 is the number of times resolved, each problem was resolved.
I still think the problem's your reference.
func uploadTheResolvedProblemsToDB(problems: [String], uid: String) {
let refDB = FIRDatabase.database().reference().child("users").child(uid).child("problems")
for problem in problems {
refDB.child(problem).runTransactionBlock({ (currentData: FIRMutableData) -> FIRTransactionResult in
var value = currentData.value as? Int
if value == nil {
value = 1
} else {
value += 1
}
currentData.value = value
return FIRTransactionResult.success(withValue: currentData)
}) { (error, comited, snapshot) in
if let error = error {
print("errorrrrr", error.localizedDescription)
}
}
}
}
I have edited your logic a little bit but I believe this is how it should work instead. I have not ran a Firebase instance on this so if there are some discrepancies, its because I cannot fully test it. I hope it helps though:
let refDB = FIRDatabase.database().reference().child("users").child(uid).child("problems")
for problem in problems {
refDB.runTransactionBlock({ (currentData:FIRMutableData) -> FIRTransactionResult in
var dataToUpdate = currentData.value as? [[String : Any]]
if var resultData = dataToUpdate {
if dataToUpdate.keys.contains(problem) {
if let timesResolved = dataToUpdate[problem] as? Int {
resultData[problem] = timesResolved + 1
}
else {
resultData[problem] = 0
}
}
else {
resultData[problem] = 0
}
if !resultData.keys.contains(problem) {
resultData[problem] = dataToUpdate[problem] ?? 0
}
currentData.value = resultData
return FIRTransactionResult.success(withValue: currentData)
}
}) {(error,commited,snapshot) in
if let error = error {
print("errorrrrr", error.localizedDescription)
}
})
}

DidSelect after SearchController is used causes crash swift

I have a TableView and a Search Controller. They both work perfectly with regards to displaying the info, searching, etc. The problem arises when you go to select one of the cells.
In my code, there are 4 ways you can select the cell... If a bool isAboutNewPost == true / false, and if the search is active or not. If the search controller is active, I am using the data from a filtered array.
When you select a cell and the search controller is not active, it works perfectly. When you select a cell and the search controller is active, but the bool is false, it works perfectly. When you select a cell and the search controller is active and the bool is true, it crashes. I have no clue why, because it is almost identical code.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//
self.resultSearchController.endEditing(true)
switch(segmentControl.selectedSegmentIndex)
{
case 0:
if self.theResultSearchController.active {
self.theResultSearchController.hidesNavigationBarDuringPresentation = false
print("it is in search")
let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! NewAddPostTableViewCell
theResultSearchController.active = false
print("Going to Did Select Name!")
// self.performSegueWithIdentifier("transferToAddChinUp", sender: currentCell.name.text)
let sb = UIStoryboard(name: "Main", bundle: nil)
if self.isAboutNewPost == true {
print("There was a new post.")
let messagesVC = sb.instantiateViewControllerWithIdentifier("AddChinUpScreen") as! AddChinUpViewController
messagesVC.userObjectId = currentCell.nameLabel.text
messagesVC.thereWasJustANewPost = true
print("i got to right here.")
self.navigationController?.pushViewController(messagesVC, animated: true)
// new line
//self.performSegueWithIdentifier("transferToAddChinUp", sender: currentCell.nameLabel.text)
} else {
print("There wasn't a new post.")
let messagesVC = sb.instantiateViewControllerWithIdentifier("AddChinUpScreen") as! AddChinUpViewController
messagesVC.userObjectId = currentCell.nameLabel.text
self.navigationController?.pushViewController(messagesVC, animated: true)
//self.performSegueWithIdentifier("didSelectName", sender: currentCell.nameLabel.text)
}
} else {
if self.isAboutNewPost == true {
print("it is not in search")
let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! NewAddPostTableViewCell
print("Going to transferToAddChinUp!")
self.performSegueWithIdentifier("transferToAddChinUp", sender: currentCell.nameLabel.text)
} else {
print("it is not in search")
let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! NewAddPostTableViewCell
print("Going to Did Select Name!")
self.performSegueWithIdentifier("didSelectName", sender: currentCell.nameLabel.text)
}
}
break
case 1:
if self.theResultSearchController.active {
self.theResultSearchController.hidesNavigationBarDuringPresentation = false
print("it is in search")
let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! NewAddPostTableViewCell
theResultSearchController.active = false
print("Going to Did Select Name!")
// self.performSegueWithIdentifier("transferToAddChinUp", sender: currentCell.name.text)
let sb = UIStoryboard(name: "Main", bundle: nil)
if isAboutNewPost == true {
print("There was a new post!!!!!!")
let messagesVC = sb.instantiateViewControllerWithIdentifier("AddChinUpScreen") as! AddChinUpViewController
messagesVC.userObjectId = currentCell.nameLabel.text
messagesVC.thereWasJustANewPost = true
self.navigationController?.pushViewController(messagesVC, animated: true)
// self.performSegueWithIdentifier("transferToAddChinUp", sender: currentCell.nameLabel.text)
} else {
let messagesVC = sb.instantiateViewControllerWithIdentifier("AddChinUpScreen") as! AddChinUpViewController
messagesVC.userObjectId = currentCell.nameLabel.text
self.navigationController?.pushViewController(messagesVC, animated: true)
// self.performSegueWithIdentifier("didSelectName", sender: currentCell.nameLabel.text)
}
} else {
if isAboutNewPost == true {
print("it is not in search")
let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! NewAddPostTableViewCell
print("Going to transferToAddChinUp!")
self.performSegueWithIdentifier("transferToAddChinUp", sender: currentCell.nameLabel.text)
} else {
print("it is not in search")
let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! NewAddPostTableViewCell
print("Going to Did Select Name!")
self.performSegueWithIdentifier("didSelectName", sender: currentCell.nameLabel.text)
}
}
break
default:
break
}
//AddChinUpScreen
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "didSelectName" {
let completeSignUpVC = segue.destinationViewController as! AddChinUpViewController
let selectedRowIndex = self.theTableView.indexPathForSelectedRow
let currentCell = theTableView.cellForRowAtIndexPath(selectedRowIndex!) as! NewAddPostTableViewCell
completeSignUpVC.userObjectId = currentCell.nameLabel.text
} else if segue.identifier == "transferToAddChinUp" {
let completeSignUpVC = segue.destinationViewController as! AddChinUpViewController
//let selectedRowIndex = self.theTableView.indexPathForSelectedRow
//let currentCell = theTableView.cellForRowAtIndexPath(selectedRowIndex!) as! NewAddPostTableViewCell
completeSignUpVC.userObjectId = sender as! String
completeSignUpVC.thereWasJustANewPost = true
} else if segue.identifier == "tappedOnProfilePicture" {
let completeSignUpVC = segue.destinationViewController as! AddChinUpViewController
completeSignUpVC.userObjectId = sender as! String
if self.isAboutNewPost == true {
completeSignUpVC.thereWasJustANewPost = true
} else {
//completeSignUpVC
}
}
}
Here is the Error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIFullscreenPresentationController adaptivePresentationController]: unrecognized selector sent to instance 0x7febc34cdf60'
*** First throw call stack:
(
0 CoreFoundation 0x00000001072e3f65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001069d5deb objc_exception_throw + 48
2 CoreFoundation 0x00000001072ec58d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000107239f7a ___forwarding___ + 970
4 CoreFoundation 0x0000000107239b28 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001084fb389 -[UISearchController _searchPresentationController] + 134
6 UIKit 0x00000001080d7755 -[_UISearchControllerTransplantSearchBarAnimator animateTransition:] + 215
7 UIKit 0x0000000107c81ede __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 2638
8 UIKit 0x0000000107b2e4be _runAfterCACommitDeferredBlocks + 317
9 UIKit 0x0000000107b407ee _cleanUpAfterCAFlushAndRunDeferredBlocks + 95
10 UIKit 0x0000000107b4c4e6 _afterCACommitHandler + 90
11 CoreFoundation 0x000000010720f9d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
12 CoreFoundation 0x000000010720f947 __CFRunLoopDoObservers + 391
13 CoreFoundation 0x000000010720559b __CFRunLoopRun + 1147
14 CoreFoundation 0x0000000107204e98 CFRunLoopRunSpecific + 488
15 GraphicsServices 0x000000010a6c0ad2 GSEventRunModal + 161
16 UIKit 0x0000000107b22676 UIApplicationMain + 171
17 Chin Up 2 0x0000000104d180fd main + 109
18 libdyld.dylib 0x0000000109a5792d start + 1
19 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I found the solution. It had to do with how the view was loaded in the first place. Commented out code was the original code. Fixed it by making it a modal segue.
#IBAction func goToUnlockPost(sender: AnyObject) {
// let vc = self.storyboard!.instantiateViewControllerWithIdentifier("NewAddPost") as! NewAddPostViewController
// vc.isAboutNewPost = true
// vc.comingFromUnlockPost = true
// self.presentViewController(vc, animated: true, completion: nil)
self.performSegueWithIdentifier("tappedUnlockPost", sender: nil)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "tappedUnlockPost" {
let destinationNavigationController = segue.destinationViewController as! UINavigationController
let targetController = destinationNavigationController.topViewController as! NewAddPostViewController
//targetController = segue.destinationViewController as! NewAddPostViewController
targetController.isAboutNewPost = true
targetController.comingFromUnlockPost = true
}
}

NSCache not thread safe in swift code?

I'm not sure if this thread unsafe in Swift,Output should be 31 characters, is such that NSCache isn't thread safe?
let nscache = NSCache()
nscache.setObject("", forKey: "1")
let globalQueue = dispatch_get_global_queue(0, 0)
dispatch_async(globalQueue) {
print(NSThread.currentThread())
for i in 0...10 {
let str = nscache.objectForKey("1") as! String + ".\(i)"
nscache.setObject(str, forKey: "1")
print("str:\(str)")
}
}
dispatch_async(globalQueue) {
print(NSThread.currentThread())
for i in 11...20 {
let str = nscache.objectForKey("1") as! String + ".\(i)"
nscache.setObject(str, forKey: "1")
print("str:\(str)")
}
}
dispatch_async(globalQueue) {
print(NSThread.currentThread())
for i in 21...30 {
let str = nscache.objectForKey("1") as! String + ".\(i)"
nscache.setObject(str, forKey: "1")
print("str:\(str)")
}
}
Output
/////////////////print/////////////////
str:.21 str:.21.11 str:.21.11.0 str:.21.11.0.22 str:.21.11.0.22.12
str:.21.11.0.22.12.1 str:.21.11.0.22.12.1.23
str:.21.11.0.22.12.1.23.13 str:.21.11.0.22.12.1.23.13.24
str:.21.11.0.22.12.1.23.13.2 str:.21.11.0.22.12.1.23.13.2.14
str:.21.11.0.22.12.1.23.13.2.25 str:.21.11.0.22.12.1.23.13.2.3
str:.21.11.0.22.12.1.23.13.2.3.15 str:.21.11.0.22.12.1.23.13.2.3.15.26
str:.21.11.0.22.12.1.23.13.2.3.15.26.4
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.5
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18.29
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18.7
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18.7.19
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18.7.19.30
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18.7.19.30.8
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18.7.19.30.8.20
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18.7.19.30.8.20.9
str:.21.11.0.22.12.1.23.13.2.3.15.26.4.16.27.17.6.28.18.7.19.30.8.20.9.10

Resources