PureLayout on device: unrecognized selector sent to instance - ios

today I found out that there is an issue with my project. I can't run it on a real device, because I am getting an 'unrecognized selector sent to instance' error when it reaches the part of code that comes from a pod that I am using. I can run the app if I comment the part with this code.
The problem here is that I did not encounter this problem before and it just came out of nothing.
Under linked frameworks and libraries, my pod is linked as 'optional', because I get 'dyld: Library not loaded' error if it is marked as 'required'. Bitcode is enabled as well, changing this didn't make any difference.
Currently I am using XCode 7.0 (7A220) and Cocoapods version 0.38.2.
I'd be glad for any given tips on this.
#Edit
I've found out, that I was able to run other pods. The issue comes with PureLayout pod.
#Edit2 Code
class MainViewController: UIViewController {
var label : UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.setupView()
}
func setupView() {
self.view.backgroundColor = UIColor.whiteColor()
label = UILabel()
self.view.addSubview(label)
label.autoPinEdgesToSuperviewEdges()
}
}
This view controller is displayed when app is launching. This code represents the whole situation as app crashes even on this simple view -
[UILabel autoPinEdgesToSuperviewEdges]: unrecognized selector sent to instance.
Edit
Same code works on release build config. Does anyone know why?

The best thing I can suggest is start all over from the vary beginning. Depending on how much code you have this might be intimidating, but it is the best I have to offer. But my advice is this: don't move onto something else until the bug is obliterated, doing so can save you a lot of stress.

Related

Use of unresolved identifier - app development with Swift Project 2

Sorry - I realise this is a complete beginner question, but I've googled for half a day now and still can't resolve the issue myself.
I'm using xCode 8.3 and trying to complete the apple - app development with swift course - end of unit project 2. I'm told (by the Apple book) I should be able to run the app without build failures, even if it isn't finished.
I get an unresolved identifier error when I add the following code to my ViewControler file, inside the class ViewController: UIViewController.
func updateUI() {
correctWordLabel.text = game.formattedWord
scoreLabel.text = "Wins: \(totalWins), Losses: \(totalLosses)"
treeImageView.image = UIImage(named: "Tree \(currentGame.incorrectMovesRemaining)")
}
xCode suggests I change it to Game.formattedWord, but when i do get 'Instance member 'formattedWord' cannot be used on type 'Game' ViewController.Swift'.
Could someone please help?
I've checked the sample code from Apple about 100 times and they are def saying it should be game.formattedWord in the code.
Thank you!
Try correctWordLabel.text = currentGame.formattedWord
I think it’s a typo.
Earlier in your code you create an instance of the Game struct called currentGame so you are accessing the formattedWord variable inside that instance. That’s why you couldn’t change it to Game. Game is like the blueprint of the struct. currentGame is your actual ‘thing’ Hope that makes some sense.

Today-Widget "Unable to load" error

From time to time widget crashing with "unable to load" error.
Is anyone know how to fix it?
Widget haven't requests to server or smth else.
Unable to load in today extension mostly appears when:
You extension crash due to some reason
It takes more memory than what is provided by the system. (Memory Limit : max 16MB approx.)
Debug your app extension to find out the exact problem.
Refer to Xcode's Debug Gauge for Memory and CPU utilization.
Edit:
Debugging today extension
You can debug your extension the same way you debug your main project. Just select that particular target scheme in your Xcode and run the project.
Now try using the breakpoints and other print statements in the extension’s code and you are good to go. Happy coding..😊
REBOOT the device.
This saved me.
I have faced this error
I used a custom view. But forgot to check Is initial viewController.
Set an entry point form "show attribute inspector" as an initial view controller
I have faced the same issue where it wasn't showing anything. Even my debug option was not working. I found an article online which helped me a lot. I would like to recommend this here.
Most of the time it is the size of the content view that crashes the widget. in that case, use this code snippet in TodayViewController.
Code snippet
override func viewWillAppear(_ animated: Bool)
{
var currentSize: CGSize = self.preferredContentSize
currentSize.height = 200.0
self.preferredContentSize = currentSize
}
Link for further research.
Make sure you have more than 0 rows
I have built a today-widget similar to Building a Simple Widget for the Today View.
I had none of the above issues. Mine was 0 row (I had no data for this particular day and hence, 0 row). I did not expect that it could be the problem since in the main-app, you can have empty table-view.
If you see unable to load message, make sure you have at least 1 row.
Set this in viewDidLoad:
extensionContext?.widgetLargestAvailableDisplayMode = .expanded
In my case NotificationCenter.framework was accidentally deleted from Link Binary With Libraries in Build Phases tab in widget target.

Unrecognised Selector when using nicklockwood's CountryPicker in Swift

I know they say there is no such thing as a stupid question, but I feel stupid since I know this question has been asked dozens of times before, but I can't seem to find one of the solutions which fit my case (I have made the effort of looking).
So the problem I face is that I am creating a Swift iOS project, and am looking to implement a country picker. From what i can tell, there is no native solution for that array of countries, so I came across what looks to be a nice custom solution by 'NickLockWood' ( https://github.com/nicklockwood/CountryPicker )
And the problem is that I am having a little trouble trying to get it to work in my Swift project, since all the sample and demo code provided is in obj-c (I am in the process of getting better at converting such code from one language to another, but I appear to not be at the ninja level yet for this..).
From what I can tell, this is how he uses it in his viewController
- (void)countryPicker:(__unused CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code
{
self.nameLabel.text = name;
self.codeLabel.text = code;
}
I have managed to try convert that into my Swift viewController as such..
func countryPicker(picker: CountryPicker?, didSelectCountryWithName name: String!, code: String!) {
println("\(name)")
println("\(code)")
}
So when the app launches, the listPicker is populated with country names and the associated flags. So I have a good feeling it is hooked up mostly correctly.
The error occurs when I spin the picker and it lands on a selection. I then get this...
exception 'NSInvalidArgumentException', reason: '-[UIViewController countryPicker:didSelectCountryWithName:code:]: unrecognized selector sent to instance 0x17dca740'
In my ViewController, where this picker is associated with, I used the storyboard to link the 'CountryPicker' delegate to the ViewController.
Then in the ViewController this is my code..
import UIKit
class RegionViewController: UIViewController, CountryPickerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func countryPicker(picker: CountryPicker!, didSelectCountryWithName name: String!, code: String!) {
println("\(name)")
println("\(code)")
}
Am I perhaps missing something else here?
Thanks!
My error.
I hadnt associated the viewController I was working on in the storyboard to use the custom RegionViewController I was trying to reach.
Fixed that connection and all was right again.
Thanks!

uppercaseString of IBOutlet UITextField.text crash

I'm running Xcode 6.3 beta 1 with iOS 8.3 beta 1 in the iOS Simulator. I have a UITextField #IBOutlet of which I'm trying to get the uppercaseString property of its text property, like this:
#IBOutlet weak var field: UITextField!
#IBAction func calledAfterUserAction(){
let capitalized = field.text.uppercaseString
}
The above workflow will cause a crash. After turning on Zombie Objects, I can see the following error:
*** -[CFString release]: message sent to deallocated instance 0x7b689cd0
How can I fix this?
I just ran into the same problem - very glad you posted this so that I knew I wasn't crazy!
I've discovered that the simple "uppercaseString" method fails with a deallocated object error, while the extended version that takes a Locale works. I'm guessing there is an internal Apple bug over handling default locales... Change your code to:
let capitalized = field.text.uppercaseStringWithLocale(NSLocale.currentLocale())

Play Sound in Swift SpriteKit project?

When I run this code.
runAction(SKAction.playSoundFileNamed("Click.mp3", waitForCompletion: false))
My app was Crashed:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Resource Click.mp3 cannot be found in the main bundle'
verify that the file exists in the project.
instantiates the variables in the file first and then make a method for breeding.
if the file exists in the project you should do the following:
var sound = SKAction.playSoundFileNamed("sound.mp3", waitForCompletion: false)
...
override func didMoveToView(view: SKView) {
playSound(sound)
//call playSound method when you want
}
func playSound(sound : SKAction)
{
runAction(sound)
}
in this mode don't crash
This may be the answer some people are looking for:
Audio files DO NOT go in Assets.xcassets!
I've had the same issue, and tried seemingly every slight code change as suggested by various StackOverflow answers, but nothing worked.
I only found this one answer that solved my issue: I had been adding my sound files to Assets.xcassets, where my graphics are. It turns out you need to add them to the project bundle (where the .swift files are, etc) — just drag the files to the Project Navigator list on the left of the screen.
Not sure why it's like this as it seems intuitive to include sound files as "Assets".
I had this exact problem for the last hour! I had to go a different route, because I tried multiple things to get this simple line of code to work and failed. It's a little more code, but this solved my problem: https://stackoverflow.com/a/24073071/586204.

Resources