[Error]: Type info TC,N,D not yet supported - ios

class ABC{
#NSManaged var liked: Bool
.....
}
in other class
class xyz{
func afunc(){
let item = ABC()
if item.liked == true{ // getting crash on this line
}}}
[Error]: Type info TC,N,D not yet supported
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[...]: unrecognized selector sent to instance 0x15d78310'
* First throw call stack:
I am simply accessing a value that I have created in a class and
its working fine on one device(ios version 8.1 and 8.3) and throwing error on another device(ios version 8.4).

I think you have created swift class. Then it should be like below :
class ABC {
var liked = Bool()
}
class XYZ {
func execute() {
let item = ABC()
if item.liked == true { // getting crash on this line
}
}
}

class ClassA: NSObject {
var liked:Bool
override init() {
liked = true
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
execute();
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func execute(){
let item = ClassA();
if item.liked==true{
print(item.liked)
}
}
}

Related

popViewController throwing "deallocated while key value observers were still registered" error

I'm having problems with deallocating an observable, even using a disposedBag. It only occurs in iOS 10.
I have to associate a TextField (SwiftMaskField) value to a variable at viewModel, so I'm doing:
class BaseViewController: UIViewController, Storyboarded {
#IBOutlet weak var txtField: SwiftMaskField!
var viewModel: BaseViewModel!
override func viewDidLoad() {
super.viewDidLoad()
bindUI()
}
private func bindUI() {
txtField.rx.text.orEmpty.bind(to: viewModel.myString).disposed(by: viewModel.bag)
viewModel.showLoading.asObservable().skip(1).subscribe(onNext: { [unowned self] in
self.showLoading()
}).disposed(by: viewModel.bag)
}
...
}
class BaseViewModel {
var showLoading = BehaviorRelay<Void>(value: ())
var myString = BehaviorRelay<String>(value:"")
let bag = DisposeBag()
func foo() {
showLoading.accept(())
}
func foo2() {
print(myString.value)
}
...
}
When I do a popViewController, my app crashes with the following error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance
0x7fbaafe45a20 of class SwiftMaskText.SwiftMaskField was deallocated
while key value observers were still registered with it. Current
observation info: (
Context: 0x0,
Property: 0x6000002596e0> )'
It only occurs in iOS 10 (haven't tested previous versions), further versions don't crash.
Also, I'm using RxSwift 5.0.
Your bag has to be above your view in the class hierarchy. Try this:
class BaseViewController: UIViewController, Storyboarded {
private let bag = DisposeBag()
#IBOutlet weak var txtField: SwiftMaskField!
var viewModel: BaseViewModel!
override func viewDidLoad() {
super.viewDidLoad()
bindUI()
}
private func bindUI() {
txtField.rx.text.orEmpty.bind(to: viewModel.myString).disposed(by: bag)
viewModel.showLoading.asObservable().skip(1).subscribe(onNext: { [unowned self] in
self.showLoading()
}).disposed(by: bag)
}
...
}
That will likely fix it, let me know if it doesn't.
Also, your view model shouldn't need a dispose bag, if it does you are probably doing something wrong in there.

Cannot find the error in this sequence. Thread 1: signal SIGABRT

I have just started to code, but I have already encountered some error which I cannot figure out. Would you please help me?
class ViewController: UIViewController {
#IBOutlet var getNumber: UITextField!
#IBAction func computePrime(_ sender: AnyObject) {
if let userString = getNumber.text { // Convert input to Int
let userNumber = Int(userString)
if let number = userNumber {
var i = 2 // Variable declaration
var prime = true
while i < number { // Prime calculation
if number & i == 0 {
prime = false
i = number
} else {
i += 1
}
}
if prime == false { // Output result
displayResult.text = "It is not prime"
} else {
displayResult.text = "It is prime"
}
} else {
displayResult.text = "Please enter a positive whole number" // Error message in case value entered is not good
}
}
}
#IBOutlet var displayResult: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
When I try to run it, the app crashes and it gives me this error:
"Thread 1: signal SIGABRT"
highlighting this line:
"class AppDelegate: UIResponder, UIApplicationDelegate {"
from the AppDelegate.swift file, which I have not modified.
How can I fix it?
Thank you!
Probably you don't have connected in Storyboard the getNumber and displayResult (IBOutlet) object.
Check that answer:
IBOutlet not connecting in SWIFT
The highlighted line is at the application delegate because the system regressed all the way back to the top trying to find a layer with an exception handler for the exception that was thrown. Check the last few lines of the Xcode console for a description of the exception which may tell you where it was caused.
You can add an "Exception Breakpoint" to stop execution at the moment of the exception to see the point of origin. Many articles exist on how to do this.

SIGABRT error in swift 2

I recently updated my app to Swift 2, and had one error, which I solved thanks to you guys.
And now, I have a second error, which is at runtime, when I press the one button to play a sound. It is a signal SIGABRT error.
Here is the error message I get in the debug console:
2016-01-25 09:16:09.019 WarningShot1.0.0[291:19030] -[WarningShot1_0_0.ViewController playMySound:]: unrecognized selector sent to instance 0x135547d30
2016-01-25 09:16:09.021 WarningShot1.0.0[291:19030] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WarningShot1_0_0.ViewController playMySound:]: unrecognized selector sent to instance 0x135547d30'
*** First throw call stack:
(0x182835900 0x181ea3f80 0x18283c61c 0x1828395b8 0x18273d68c 0x18755fe50 0x18755fdcc 0x187547a88 0x18755f6e4 0x18755f314 0x187557e30 0x1875284cc 0x187526794 0x1827ecefc 0x1827ec990 0x1827ea690 0x182719680 0x183c28088 0x187590d90 0x10005e2e0 0x1822ba8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
Also, this is the part of the code where it throws this error, in the second line, where the class is declared:
import UIKit
#UIApplicationMain
-> class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
What is happening here? What am I missing / misnaming? What do I need to change in my code to get ot running again. This app is ridiculously simple, and worked for months under the last version of Swift. Why is it now giving me errors?
Thank you for your help.
Here is the code for my ViewController.swift file:
import UIKit
import AVFoundation
import CoreMotion
class ViewController: UIViewController {
var myPlayer = AVAudioPlayer()
var mySound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("RemSound_01", ofType: "wav")!)
func initYourSound() {
do {
try myPlayer = AVAudioPlayer(contentsOfURL: mySound, fileTypeHint: nil)
myPlayer.prepareToPlay()
// myPlayer.volume = 1.0 // < for setting initial volume, still not perfected.
} catch {
// handle error
}
var motionManager = CMMotionManager()
var currentMaxAccelY : Double = 0.0
func viewDidLoad() {
super.viewDidLoad()
initYourSound()
// Do any additional setup after loading the view, typically from a nib.
//set motion manager properties
motionManager.accelerometerUpdateInterval = 0.17
//start recording data
// motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue(), withHandler: {
// (accelerometerData: CMAccelerometerData!,error:NSError!) -> Void in
// self.outputAccelerationData(accelerometerData.acceleration)
// if(error != nil) {
// print("\(error)")
// }
// })
motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: {
(accelerometerData,error) in outputAccelerationData(accelerometerData!.acceleration)
if(error != nil) {
print("\(error)", terminator: "")
}
})
}
//func outputAccelerationData(acceleration : CMAcceleration){
// accY?.text = "\(acceleration.y).2fg"
//if fabs(acceleration.y) > fabs(currentMaxAccelY)
//{
// currentMaxAccelY = acceleration.y
//}
// maxAccY?.text = "\(currentMaxAccelY) .2f"
//}
func outputAccelerationData(acceleration : CMAcceleration){
if fabs(acceleration.y) >= 1.25 {
myPlayer.play()
}
}
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func playMySound(sender: AnyObject) {
myPlayer.play()
}
// self.resetMaxValues()
// #IBOutlet var accY: UILabel!
// #IBOutlet var maxAccY: UILabel!
// #IBAction func resetMaxValues() {
// currentMaxAccelY = 0
// }
}
}
"unrecognized selector sent to instance" means that there is a mismatch between the action-name in "addTarget()" and the name of the function you want to call. Probably something with the parameters of the function.. It's hard to say without seeing any code.
action: Selector("playMySound:")
would expect to find a function:
func playMySound(sender: AnyObject?) {};
To easier track what's happening, you might add a symbolic breakpoint for all exceptions. You do that in Xcode on the "exceptions" tab (left part of the window) and when an exception is thrown, Xcode stops like usual and you might look up the stack trace. If the call is synchronous, you should easily find and see your mistake.
EDIT: Oh well, you seem to have done the user interface using a XIB file. The mistake could be, you wired the button's action in the XIB file to the view controller. If you later change the method's signature (parameter, name, etc.), UIKit can't find the method. Open the XIB and fix your error. ;-)

Swift Core data Error when trying to populate

I'm new with swift and got a problem with core data.
My app crashes when trying to populate. I just have 1 field as for testing purposes
import UIKit
import SwiftyJSON
import CoreData
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
seedRestaurantList()
fetch()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func fetch() {
let moc = DataController().managedObjectContext
let nameFetch = NSFetchRequest(entityName: "RestaurantList")
do {
let fetchedName = try moc.executeFetchRequest(nameFetch) as! [RestaurantList]
print(fetchedName.first!.name!)
} catch {
fatalError("merda again: \(error)")
}
}
func seedRestaurantList () {
let moc = DataController().managedObjectContext
let entity = NSEntityDescription.insertNewObjectForEntityForName("RestaurantList", inManagedObjectContext: moc) as! RestaurantList
entity.setValue("teste", forKey: "name")
do {
try moc.save()
} catch {
fatalError("deu merda: \(error)")
}
}
}
This is the error that I get
2015-11-02 17:38:04.880 DinDins[2993:1252158] CoreData: error: Illegal
attempt to save to a file that was never opened. "This
NSPersistentStoreCoordinator has no persistent stores (unknown). It
cannot perform a save operation.". No last error recorded. 2015-11-02
17:38:04.885 DinDins[2993:1252158] * Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'This
NSPersistentStoreCoordinator has no persistent stores (unknown). It
cannot perform a save operation.'
* First throw call stack: (0x236c585b 0x3503adff 0x2346da89 0x2346dc95 0x2346de2d 0x2347710f 0x1249d03 0x12534fb 0x23468ef1
0x233b31f3 0x233b3223 0x233d615b 0x9cff0 0x9c360 0x9c400 0x277f9f55
0x278b6c4f 0x278b6b45 0x278b5ef1 0x278b5b27 0x278b577d 0x278b56f7
0x277f5cc3 0x270bdb05 0x270b9201 0x270b9091 0x270b85b1 0x270b8263
0x270b1a1f 0x23688091 0x23686387 0x235d90f9 0x235d8ecd 0x27867607
0x278622dd 0x9fde0 0x35788873) libc++abi.dylib: terminating with
uncaught exception of type NSException (lldb)
Thanks in advance
---RestaurantList+CoreDataProperties.swift
import Foundation
import CoreData
extension RestaurantList {
#NSManaged var name: String?
}
---RestaurantList.swift
import Foundation
import CoreData
class RestaurantList: NSManagedObject {
// Insert code here to add functionality to your managed object subclass
}
Ricardo, try reseting your simulator. Open the Simulator, go to menu Simulator and select Reset content and Settings

Swift error about consecutive declarations on a line

I don't understand what's wrong with this code in my View Controller, the very bottom line (with the single } bracket) keeps getting two errors, one that states "Consecutive declarations on a line must be separated by ';'" and "expected declaration". When I add the semicolon where it directs me to it still says an expected declaration error....but for what? Can anyone find anything wrong with it?
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var testObject = PFObject(className:"TestObject")
testObject["foo"] = "bar"
testObject.saveInBackgroundWithTarget(nil, selector: nil)
var voteCount = PFObject(className:"VoteCount")
voteCount["votes"] = 0
voteCount["optionName"] = "Crepes"
voteCount.incrementKey("votes")
voteCount.saveEventually()
var query = PFQuery(className:"VoteCount")
query.getObjectInBackgroundWithId("e8KhneiSfw") {
(voteCount: PFObject!, error: NSError!) -> Void in
if error != nil {
NSLog("%#", error)
} else {
voteCount["votes"] = 1
voteCount.incrementKey("votes")
voteCount.saveEventually()
}
}
class Counter {
var voteCount: Int = 0
func incrementBy(amount: Int, numberOfTimes times: Int) { voteCount += amount * times
}
}
func didReceiveMemoryWarning() {
didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
There's a missing closing brace before this line:
class Counter {
Your viewDidLoad() method is not properly closed, so what happens is that the class and didReceiveMemoryWarning are defined as local to viewDidLoad.
A proper indentation usually reveals errors like that... are you properly indenting your code?
As written, class Counter and func didReceiveMemoryWarning() are inside viewDidLoad. Fix your braces.

Resources