Ios11 Changing Calendar From Gregorian To japanese or Buddhist Crash? - iphone

var datePickerView: UIDatePicker = UIDatePicker()
override func viewDidLoad() {
super.viewDidLoad()
initializeBarButtons() }
func initializeBarButtons() {
datePickerView.datePickerMode = UIDatePickerMode.date // This is the line that gets the error
datePickerView.addTarget(self, action: #selector(EmployeeDetailEditViewController.handleDatePicker), for: UIControlEvents.valueChanged)
}
This commented line is causing the crash when the calendar is changed from Gregorian to Buddhist.
Crash : -
Terminating app due to uncaught exception 'NSRangeException', reason:
'* -[__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond
bounds [0 .. 1]'
* First throw call stack: (0x18626e364 0x1854b4528 0x186206e9c 0x186136840 0x18f9a1890 0x1902238a8 0x19022045c 0x1902210f4
0x19022139c 0x190214254 0x1902136cc 0x190213c08 0x190213d24
0x1013881e0 0x101386d1c 0x101387018 0x18f768590 0x18f768304
0x18f8d2bd4 0x18f7f5c4c 0x18f7f5890 0x18f7f5790 0x1a53e4c18
0x18f74cf00 0x18a2b1998 0x18a2b5b20 0x18a22236c 0x18a249b90
0x18a24a9d0 0x186215edc 0x186213894 0x186213e50 0x186133e58
0x187fe0f84 0x18f7b367c 0x10131b378 0x185c5056c) libc++abi.dylib:
terminating with uncaught exception of type NSException
How to Solve This ?

Unfortunately, you can't solve it, as there is an open radar on it (https://openradar.appspot.com/41120005).
Meanwhile, use #Amey workaround:
if #available(iOS 11.0, *) {
let gregorianCalendar = Calendar(identifier: .gregorian)
self.datePickerView.calendar = gregorianCalendar
} else {
// Fallback on earlier versions
}

Related

SwiftUI embed youtube -[__NSArrayM length]: unrecognized selector sent to instance

I'm trying to embed an youtube video in swiftUI app (building for iOS 14)
i'm using CocoaPods with the following Podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '14.0'
target 'TestProjectYoutube' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for TestProjectYoutube
pod 'Alamofire', '~> 5.0'
pod 'SwiftyJSON', '~> 4.0'
pod 'URLImage'
pod 'Introspect'
end
I've created the following view
import SwiftUI
import CoreData
struct ContentView: View {
#Environment(\.managedObjectContext) private var viewContext
var body: some View {
VStack() {
VideoView(videoID: "CX-BdDHW0Ho")
}
}
}
struct VideoView: UIViewRepresentable {
let videoID: String
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView(frame: CGRect(x: 0.0, y: 0.0, width: 0.1, height: 0.1))
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
guard let youtubeURL = URL(string: "https://www.youtube.com/embed/\(videoID)") else { return }
uiView.scrollView.isScrollEnabled = false
uiView.load(URLRequest(url: youtubeURL))
}
}
The error i got is:
2023-01-16 15:35:16.130698+0100 app[44720:3273388] -[__NSArrayM length]: unrecognized selector sent to instance 0x2824115c0
2023-01-16 15:35:16.130920+0100 app[44720:3273388] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x2824115c0'
*** First throw call stack:
(0x18048bc80 0x197cb1ee4 0x18055c708 0x18042556c 0x18042477c 0x18ac78644 0x18e74ce50 0x18e9d0ca4 0x18e9d0888 0x18e94c418 0x18e963de0 0x18ecdd224 0x18ecdcec8 0x18e72b69c 0x18e727c4c 0x18e72cd18 0x18ac73590 0x18ac7410c 0x1804ac468 0x1804bc598 0x1803fe774 0x180403e48 0x180417194 0x1a0f56988 0x182c1aa88 0x1829b3fc8 0x187c6cd68 0x187bb783c 0x187b9d1dc 0x10281f3fc 0x10281f530 0x102ff84d0)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x2824115c0'
terminating with uncaught exception of type NSException
When I replace the youtube.com with google.com, i dont get the error and google is loaded.
Can someone help me with this?

Swift: animating uilayoutconstraints and changing alpha causes crash

Why is this code causing a SIGABT error?
#IBAction func showDial(_ sender: Any) {
var dialBottom:CGFloat = lcDialBottom!.constant
if dialBottom == -600 {
//move up
dialBottom = -400
} else {
//move down
dialBottom = -600
}
UIView.animate(withDuration: 0.3,
animations: {
self.lcDialBottom.constant = dialBottom
self.view.layoutIfNeeded()
self.view.updateConstraintsIfNeeded()
self.btnShowDial.alpha = 0.0
})
}
Error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSLayoutConstraint setAlpha:]: unrecognized selector sent to instance 0x600002ff8d70'
I understand what the error is saying, NSLayoutConstraint does not have a setAlpha method, but I'm not calling it on a NSLC, I'm calling set alpha on a UIButton, which does have a setAlpha.
Here's my properties:
#IBOutlet weak var btnShowDial: UIButton!
#IBOutlet weak var lcDialBottom: NSLayoutConstraint!
Check connection of btnShowDial in storyboard. Maybe you connected this IBOutlet with layout constraint.

Unrecognized selector sent to instance, reason: '-[UITouchesEvent rightView]

My app crashes and throws this error
[UITouchesEvent rightView]: unrecognized selector sent to instance 0x13d5092e0
2016-08-04 17:07:15.569 [3809:1375151]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITouchesEvent rightView]: unrecognized selector sent to instance 0x13d5092e0'
*** First throw call stack:
(0x180d72db0 0x1803d7f80 0x180d79c4c 0x180d76bec 0x180c74c5c 0x1000e681c 0x1000e6a60 0x185f08be8 0x185f08b64 0x185ef0870 0x185f11360 0x185f07ed8 0x185f00c20 0x185ed104c 0x185ecf628 0x180d2909c 0x180d28b30 0x180d26830 0x180c50c50 0x182538088 0x185f3a088 0x1000f5c88 0x1807ee8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm trying to make a custom class for hide and show password so that I can use it in any UITextField in any UIViewController.
class HideShowIcon:NSObject {
var showPasswordImage = UIImage(named: "ic_show_password") as UIImage?
var hidePasswordImage = UIImage(named: "ic_hide_password") as UIImage?
func hideShowPasswordButton(hideText:UITextField) {
var hideShowSize: CGSize = "12345".sizeWithAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14.0)])
var hideShow: UIButton = UIButton(type: UIButtonType.System)
hideShow.frame = CGRect(x: 0, y: 0, width: hideShowSize.width, height: hideText.frame.size.height)
hideShow.setImage(hidePasswordImage, forState: UIControlState.Normal)
hideText.rightView = hideShow
hideText.rightViewMode = UITextFieldViewMode.Always
hideShow.addTarget(self, action: #selector(HideShowIcon.hideShowPasswordTextField(_:hideText:)), forControlEvents: UIControlEvents.AllTouchEvents)
}
func hideShowPasswordTextField(sender: AnyObject,hideText:UITextField) {
var hideShow: UIButton = (hideText.rightView as? UIButton)!
if !hideText.secureTextEntry {
hideText.secureTextEntry = true
hideShow.setImage(hidePasswordImage, forState: UIControlState.Normal)
} else {
hideText.secureTextEntry = false
hideShow.setImage(showPasswordImage, forState: UIControlState.Normal)
}
hideText.becomeFirstResponder()
}
}
You can not use selector with many parameters hideShowPasswordTextField(_:hideText:) for UIButton target. You can only use selector with one (or zero) parameter, in which UIButton will put itself: hideShowPasswordTextField(_:)
func hideShowPasswordTextField(sender: UIButton) {
//...
}
To use hideText in this function, you may declare it as property of your class:
var hideText: UITextField!
and assign value to it in class initialization step

Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x156b9090> was mutated while being enumerated.'

I'm currently working with Swift in SpriteKit to make a small/basic mini game, and I'm running into the error displayed in the title above...
Most of the time, everything works fine, but every once in a while, I get this error (the majority of the times it happens, it's right when the game over function seen below gets called). The error always points to the following line:
func handle_tilt(acceleration_data: CGFloat)
{
if ((childNodeWithName("hero")) != nil){
childNodeWithName("hero")?.physicsBody?.applyForce(CGVectorMake(acceleration_data * 50, 0))
}
}
How can I fix this?
**the code for the accelerometer set up below is contained in the
if motionManager.accelerometerAvailable == true {
self.motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue()) {
(data, error) in
if (data.acceleration.y != 0) {
self.motionManager.accelerometerActive == true
self.handle_tilt(CGFloat(data.acceleration.y))
}
}
}
The function which, when called, triggers the error...
func game_over()
{
self.removeActionForKey("spawn_flying_squirrels")
self.removeActionForKey("spawn_flying_squirrels")
println("Removed the actions")
self.motionManager.stopAccelerometerUpdates()
println("removed motion manager")
if let recognizers = self.view?.gestureRecognizers {
for recognizer in recognizers {
self.view!.removeGestureRecognizer(recognizer as! UIGestureRecognizer)
}
}
println("removed the gesture recognizers")
//saves the score or doesn't (if it doesn't make the high score
saveScore(score)
for child in self.children as! [SKNode]
{
removeChildrenInArray([child])
}
println("removed the children")
let scene = GameScene(size: self.size)
scene.scaleMode = .AspectFill
NSLog("HE DEAD")
view?.presentScene(scene)
}
What I think is happening is that the game_over function deletes the "hero" node, and then the handle_tilt function tries unsuccessfully to access "hero" leading to a meltdown. I tried to prevent it with the if statement in the handle_tilt function, but it wasn't a complete success like I had hoped...

LBBlurredImage NSInvalidArgumentException

I'm using the following library:
https://github.com/lukabernardi/LBBlurredImage
This is the code I'm using to blur my background image that I'm adding to a ViewController:
var background = UIImage(named: "bg")
var backgroundImageView = UIImageView(image: background)
backgroundImageView.contentMode = .ScaleAspectFill;
backgroundImageView.setImageToBlur(background, blurRadius: 10, completionBlock: { () -> Void in
println("The blurred image has been set")
})
self.view.addSubview(backgroundImageView)
I'm getting the following error and I'm not sure why:
-[UIImageView setImageToBlur:blurRadius:completionBlock:]: unrecognized selector sent to instance 0x7ff08a802390
2015-01-27 10:50:44.326 TestApp[9289:66346] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setImageToBlur:blurRadius:completionBlock:]: unrecognized selector sent to instance 0x7ff08a802390'
UPDATE:
Looks like I'm not the only one to receive the error.
Exception was that the image I was passing was nil and in turn it was violating NSParameterAssert(image);
var background = UIImage(named: "bg")
Instead of this try to specify the full path of the image.
It worked for me and I am pretty sure it will work for you too.
You can also try this path with your code
var background = UIImage(named: "Images/bg");