IBInspectable attributes not appearing in Xcode 8 "user defined runtime attributes" area? - swift3

I'm running XCode 8.1 and can not get my IBInspectable attributes appearing in Xcode. Any known issues with XCode 8.1 (swift 3) in this area? Or any issues with what I'm trying to do here?
Steps:
Create a simple IOS app
Created the following "customControl" class
In the app storyboard, drag a UIView onto the storyboard, and then change the class type of the "customControl"
I note XCode going through the "refresh views" stage, however no items get added to the "user defined runtime attributes" area?
Code:
import UIKit
#IBDesignable
class customControl : UIView {
#IBInspectable
var customAttribute: UIColor = UIColor.blue
}

Related

PreviewDevice not showing up in preview

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewDevice(PreviewDevice(rawValue: "iPhone 11"))
}
}
However, the device is not shown in the preview. I ran "xcrun simctl list devicetypes" in terminal which does show the simulator. Is this normal behavior or am I missing something. The goal is that I want to show how the app looks with the iPhone resolution. I am using xCode 13.
I have meet same issue at Xcode Version 14.1 (14B47b).
In my case ,this is because an unavailable simulator model has been selected like "iPhone 11",Xcode automatically chooses a available preview device based on your currently selected run destination.
Like this:
(selected iPhone SE2 but automatically chooses iPhone14 Pro)
Press control and option, click previewDevice, and then select an available model in the inspector can fix it:
(iPhone 14 selected, preview shows as expected)
If there is no model you want in these options, you can add it in the menu Window -> Devices and Simulators first.
Hope this helps you.

Navigation view is hiding while pushing from SwiftUI views to Storyboard project in iOS13

I have added SwiftUI views in my existing swift project.
I have the following flow in the project
FirstViewController --NavigationPush -> SwiftUIView1 -NavigationLink->
SwiftUIView2 - NavigationLink-> SwiftUIView3 - NavigationLink
(UIViewRepresentable) -> SecondViewController.
till SwiftUIView3 everything works as expected. while pushing from SwiftUIView3 -> SecondViewController, even though I'm setting the navigation property isHidden = false,
the navigationBar appears in the controller for a fraction of sec and disappears. I have tried to unhide navigation in all the controller life cycle methods. But nothing happens. Please let me know your suggestion to resolve this.
FYI, below code, I used SwiftUI to hide the navigation bar.
Code Block
.navigationBarTitle("") // This should be empty.
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)

SwiftUI Canvas is blank or has crashed?

My SwiftUI Canvas has disappeared. Has it crashed? I don't see any output in the console.
I have macOS 10.15 Catalina (the requirement for SwiftUI) and Xcode 11+.
Solution 1
If your SwiftUI view were named "TestView," the following would be necessary to display the Canvas:
#if DEBUG
struct TestView_Previews : PreviewProvider {
static var previews: some View {
TestView()
}
}
#endif
Simply copy the above code and change the instances of "TestView" to whatever your file is called. Click "Resume" and the canvas should load up.
Solution 2
If the above did not work, try to clear the derived data from the machine by first closing Xcode, then navigating in Finder to
~/Library/Developer/Xcode/DerivedData
Drag all of the files to the trash and restart Xcode. Don't worry, none of your code will be deleted, this is just the data that Xcode creates to help it to compile your project faster.

Titanium Hyperloop casting ListView to UIScrollView to use flashScrollIndicators

I want to flash the scrollbars of a ListView in Axway / Appcelerator Titanium. So I cast a Titanium ListView to a iOS UIScrollView and then try to call the flashScrollIndicators method on it, but I get an exception. Does anyone now how to accomplish this? See my code below:
-- View
<Alloy>
<Window onOpen="onWindowOpen">
<ListView id="listView">
etc...
-- Controller
// After displaying the ListView I call:
var UIScrollView = require('UIKit/UIScrollView');
var listView = UIScrollView.cast($.listView);
listView.flashScrollIndicators();
The $.listView object is natively a subclass of UIView, not a UIScrollView. It contains a UITableView as a child view. You could access the tableview like this:
var UIView = require('UIKit/UIView');
var listView = UIView.cast($.listView);//you cast it to be able to access it's native properties
listView.tableView.flashScrollIndicators();
Haven't tested it but I guess it should work.
When in doubt about the type of a Titanium UI element, just go and check the source code by opening the project compiled in the build/iphone directory. Open it with XCode and search for the header file.

Button visibly clicking but event not registering

Swift 3/iOS 10/Xcode 8
I have a view controller (pieChart) that contains a label, two buttons and an empty view (which will contain a pie chart). The label and two buttons are incorporated into a horizontal stack view, which lies above the pie chart view.
The above VC is embedded into one of four container views (The main screen of the app is comprised of these four container views) when the app starts up.
In pieChart, I have linked both buttons up to their respective IBActions and IBOutlets. When clicking on button 2, a modal segue should occur to another VC but this does not happen. Visibly, the button is registering the click - ie it changes colour when you click it. I have placed a print statement in the IBAction method for button 2 but this too does not display. No error messages are displayed in console either.
The only reasons for this occurring that I have found after several hours of hunting are:
sub views have been added to the button itself so the click event signal passes by the button to be received by the added sub views. This is not the case for me. Order is Main App Window > Container View > Embedded VC > Stack View > Button. InteractionEnabled is set to true for all.
Button lies partially outside containing view (it's height/width might be greater than its containing view). This is not the case for me. The stack view, label and both buttons share the same height and the width of the stack view is equal to the sum of the widths of the label and buttons plus the spacing between the label and buttons.
I have also tried adding an event handler programmatically with:
SelectAnalyisButtonOutlet.addTarget(self, action: #selector(SelectAnalysisButtonClicked), for: .touchUpInside)
but the same outcome occurs.
Are there any other reasons for the click events seemingly not registering?
EDIT 1
The pieChart VC mentioned above is one of several VC's that are swapped out of the same container view (called detailContainerView), depending on which button (all of which work just fine) is clicked in one of the OTHER container views (called TabBar).
I placed a button in each of two other VC's that get displayed in detailContainerView and hooked them each up to an IBAction. Each IBAction contains a print statement that fires when the button is clicked. At the moment then, these two VC's only consist of a label and the newly inserted buttons. None of the buttons worked when I ran the app.
I then set one of the VC's of detailContainerView as the Initial View Controller in the Attributes Inspector and re-ran the app. Suddenly the buttons now work! If I then hook the buttons up to a segue, the segues work too!
Something seems to change when I swap out the VC's in detailContainerView. The code I am using to swap the VC's out is as follows:
func SwapOutControllers(vc: UIViewController, vcName: String){
//REMOVE OLD VC
detailPaneVCReference?.willMove(toParentViewController: nil)
detailPaneVCReference?.view.removeFromSuperview()
detailPaneVCReference?.removeFromParentViewController()
var newVc: UIViewController?
switch vcName {
case "Biography":
newVc = vc as! Biography
case "Social Media":
newVc = vc as! SocialMedia
case "News Feed":
newVc = vc as! NewsFeeds
case "Stats":
newVc = vc as! StatsAboutParliament
case "Petitions":
newVc = vc as! Petitions
default:
print("Error: No VC Found!")
}
//ADD NEW VC
ParentVC?.addChildViewController(newVc!)
let width = detailContainerView?.frame.width
let height = detailContainerView?.frame.height
newVc?.view.frame = CGRect(x: 0, y: 0, width: width!, height: height!)
detailContainerView?.addSubview((newVc?.view)!)
newVc?.didMove(toParentViewController: ParentVC)
}
detailPaneVCReference is a reference to whichever VC is currently being displayed by detailContainerView. ParentVC is the VC that contains the four container views.
The VC that is removed from the ParentVC still exists in the debugging view hierarchy after it has been removed/swapped out - could this be somehow blocking the click event from reaching the event handler?
SOLUTION!
The source of my problem has been that the references I had made to each of the view controllers that get swapped in and out of detailContainerView were incorrectly declared as weak references. I deleted "weak" (eg "weak var x: UIViewController?" --> "var x: UIViewController?") from each of the declarations and voila!, the code now works as intended!
The source of my problem has been that the references I had made to each of the view controllers that get swapped in and out of detailContainerView were incorrectly declared as weak references. I deleted "weak" (eg "weak var x: UIViewController?" --> "var x: UIViewController?") from each of the declarations and voila!, the code now works as intended!