I'm running Xcode Version 10.2.1 (10E1001) on MacBook Pro 2016
Processor: 2.6 GHz Intel Core i7
Memory: 16 GB 2133 MHz LPDDR3
Graphic: Radeon Pro 450 2 GB and Intel HD Graphics 530 1536 MB
Storage: 256GB SSD
Free Storage: 45GB SSD
When i try to open storyboards i see a Storyboard with transparent ViewControllers but those ViewControllers already have UIViews and backgrounds but Xcode doesn't show,This remains for more than 20 minutes, then UIViews appear
This is how my #IBInspectable class looks like:
import Foundation
import UIKit
#IBDesignable
class BorderButton: UIButton {
#IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
}
override init(frame: CGRect) {
super.init(frame: frame)
}
}
Im getting error The agent crashed:
See picture below:
What i've done:
Cleaning build folder
Removing Derived Data
Close Xcode and re open
Free up ram
Solutions from this question
but none of above worked for me.
Related
iOS 13 brings in some handy extensions that I have quite a while now; I'd like to retain my code for iOS 11 and 12 and use built-in for iOS 13:
extension CIImage {
// if iOS 13 not available
open class var black: CIImage { return CIImage(color: .black) }
}
Unable to add more than three UILabels to a UIViewController’s view in the IPad Playgrounds app. Is it me or the system?
Simplified code to show the issue. Hardware is a 2018 iPad Pro running iOS 12.3.1 Playgrounds app 3.0. Using UIViews up to five can be added successfully.
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
let square50 = CGSize(width: 50, height: 50)
override func viewDidLoad() {
var myFrame = CGRect(origin: .zero, size: square50)
for index in 0...4 {
view.addSubview(UIView(frame: myFrame)) // fails at 6th!
(view.subviews[index] as! UIView).backgroundColor = .red
myFrame.origin.y += 80
}
}
}
PlaygroundPage.current.liveView = MyViewController()
With the index range set as shown the code worked as expected, displaying the set number of coloured rectangles. With the range increased to 0...5 the runtime stopped with the message “There was a problem encountered while running this playground. Check your code for mistakes”.
Just been able to test the code on Xcode 10.3 under OS X 10.16.6 on my iMac Retina 5k 27" late 2015. There is NO problem with the code and there is no short-range limit on the number of sub-views that can be created.
The problem rests with iOS Swift Playgrounds 3.0 running on an iPad Pro 12.9 inch 3rd-gen using iOS 12.3.1. This is therefore a bug!
In My case i am changing my layouts of the view depending on the traitCollection.horizontalSizeClass
Here is my Code snippet .
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.horizontalSizeClass == .regular {
// 2
NSLayoutConstraint.deactivate(compactConstraints)
NSLayoutConstraint.activate(regularConstraints)
// 3
socialMediaView.axis = .horizontal
} else {
// 4
NSLayoutConstraint.deactivate(regularConstraints)
NSLayoutConstraint.activate(compactConstraints)
socialMediaView.axis = .vertical
}
}
Every things working as directed in iphone 7 plus and iphone x in portrait-mode
and in landscape mode i want the rabbit image comes to left side and the stackview of all socialMedias axis will be horizontal
but in iphone X landscape mode its not coming while in phone 7 its coming .Check the below screen shots
Looking at your question and condition, I found a problem in your condition. you should check for the verticalSizeClass instead of horizontalSizeClass.
WHEN CHECK FOR HORIZONTAL SIZE CLASS.
IN PORTRAIT: All iPhone Devices has compact width, so every time, it will go to else condition and set the view properly.
IN LANDSCAPE: All iPhone Plus (iPhone 6s Plus, iPhone 7 Plus and iPhone 8 plus) Devices has Regular width and All other iPhone (iPhone 6s, 6SE, iPhone 7 and iPhone 8, iPhone X) Devices has Compact width, so for all plus devices it will works fine but not for others.
FOR PORTRAIT:
FOR LANDSCAPE:
For more, read official doc here
So, update your code to this.
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.verticalSizeClass == .regular {
NSLayoutConstraint.deactivate(compactConstraints)
NSLayoutConstraint.activate(regularConstraints)
socialMediaView.axis = .horizontal
} else {
NSLayoutConstraint.deactivate(regularConstraints)
NSLayoutConstraint.activate(compactConstraints)
socialMediaView.axis = .vertical
}
}
Try and share the results.
I'm developing swift based iOS application for iPhone family. My application supports all devices start from iPhone 4s to iPhone X. Labels appears bigger in smaller devices like iPhone 4s as I added bigger font size for high end devices. Can someone help me on how to scale the font according to device. I tried size classes with compact/regular width and compact/regular height but none of them helped me. Your help is very much appreciated
Programmatically
Without using the storyboard I have the approach to simply change the font size depending on the screen width like so:
func dynamicFontSize(_ FontSize: CGFloat) -> CGFloat {
let screenWidth = UIScreen.main.bounds.size.width
let calculatedFontSize = screenWidth / 375 * FontSize
return calculatedFontSize
}
and can be used as:
myLabel.font = UIFont(name: "Helvetica", size: dynamicFontSize(20))
Note that in the dynamicFontSize function the number 375 is simply the basis for the font size calculation, because I usually test my app on iPhone 8 (i.e. font size 18 is actually 18 on an iPhone 8 due to its actual width of 375). This number can be altered to your liking.
Storyboard
If you insist on using storyboard, you can instead create a new swift file subclassing UILabel and use an #IBInspectable like so:
import UIKit
class UILabelFontClass: UILabel {
#IBInspectable var DynamicFontSize: CGFloat = 0 {
didSet {
overrideFontSize(FontSize: DynamicFontSize)
}
}
func overrideFontSize(FontSize: CGFloat){
let fontName = self.font.fontName
let screenWidth = UIScreen.main.bounds.size.width
let calculatedFontSize = screenWidth / 375 * FontSize
self.font = UIFont(name: fontName, size: calculatedFontSize)
}
}
Inside storyboard subclass UILabelFontClass to your label:
And now in the Attributes inspector, you can set the font size:
You can try label hight according to view in storyboard .
with this image reference i done with iPhone 5s screen size and give label hight equal to hight in multiplier 30/554
Instead of making different class for UILabel. You can make UILabel Extension and use this IBDesignable Solution to set values from Storyboard.
Here Base width is 375pt
extension UILabel{
#IBInspectable
var scaleSize: CGFloat {
set {
let fontName = self.font.fontName
let screenWidth = UIScreen.main.bounds.size.width
let calculatedFontSize = screenWidth / 375 * newValue
self.font = UIFont(name: fontName, size: calculatedFontSize)
}
get {
return self.scaleSize
}
}
}
My SpriteKit app (named CurlShots) is crashing at launch when it is trying to present the first scene (the main menu). Everything works fine in simulator and devices with debug builds but with an archived build that I'm installing with iTunes I'm getting a crash in didMoveToView of the menu scene.
#objc class MenuScene: SKScene {
...
Last Exception Backtrace:
0 CoreFoundation 0x18673c2d8 __exceptionPreprocess + 132
1 libobjc.A.dylib 0x197be80e4 objc_exception_throw + 60
2 CoreFoundation 0x186743290 +[NSObject(NSObject) doesNotRecognizeSelector:] + 220
3 CoreFoundation 0x186740154 ___forwarding___ + 928
4 CoreFoundation 0x186642ccc _CF_forwarding_prep_0 + 92
5 CurlShots 0x10011b208 function signature specialization of CurlShots.MenuScene.didMoveToView (CurlShots.MenuScene)(ObjectiveC.SKView) -> () (MenuScene.swift:71)
6 CurlShots 0x100116c80 #objc CurlShots.MenuScene.didMoveToView (CurlShots.MenuScene)(ObjectiveC.SKView) -> () (MenuScene.swift:0)
7 SpriteKit 0x18afd7770 -[SKScene _didMoveToView:] + 88
8 SpriteKit 0x18afef004 -[SKView presentScene:] + 264
9 CurlShots 0x10012801c function signature specialization of CurlShots.GameViewController.viewWillLayoutSubviews (CurlShots.GameViewController)() -> () (GameViewController.swift:70)
I'm using auto layout and viewDidLoad of the VC has no code. Instead, I'm presenting the scene from viewWillLayoutSubviews because I need the device screen size for initializing the scene
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
let skView = self.view as! SKView
if skView.scene == nil
{
skView.showsFPS = false
skView.showsNodeCount = false
skView.ignoresSiblingOrder = true
let mainMenu = MenuScene(size: skView.bounds.size)
mainMenu.scaleMode = .AspectFill
skView.presentScene(mainMenu)
}
}
I've tried to remove all code from didMoveToView of the menu scene but that has no effect. Also tried commenting out variables in the menu scene although none of them were conditional. I tried to retain the mainMenu scene in a variable to avoid it being released but that did not solve the crash. Also tried overriding the init(size) of the scene to verify that the menu scene actually gets created before it is presented.
Don't know what else to try. Because the crash only happens in archived package I cannot debug by setting breakpoints.
Did you make sure to set the Main Menu as your first view by going to story board and on the right panel selecting "set view as first view" ( or something like that )? sometimes this throws this error. May not be the overall solution but it is worth checking
I found a solution to the problem by meticulously removing code lines until I found the root cause. This looks more like a bug on the Apple side but anyways changing one code line fixed the crash.
The crash was caused by the scene to be presented. Inside didMoveToView I was checking whether the device is an iPad by using UIUserInterfaceIdiom and for some reason swift did not like that in release build. I'm calculating a scaling factor per the screen width in the code so now I use that info to determine whether the device is an iPad. So, the code change that I did was to replace line
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad) {
with a line
if(scaling > 2.0) { // if iPad