Posts

Showing posts with the label swift

ARKit Place a SCNNode facing the camera

ARKit Place a SCNNode facing the camera I'm using ARKit to display 3D objects. I managed to place the nodes in the real world in front of the user (aka the camera). But I don't manage to make them to face the camera when I drop them. ARKit let tap_point=CGPoint(x: x, y: y) let results=arscn_view.hitTest(tap_point, types: .estimatedHorizontalPlane) guard results.count>0 else{ return } guard let r=results.first else{ return } let hit_tf=SCNMatrix4(r.worldTransform) let new_pos=SCNVector3Make(hit_tf.m41, hit_tf.m42+Float(0.2), hit_tf.m43) guard let scene=SCNScene(named: file_name) else{ return } guard let node=scene.rootNode.childNode(withName: "Mesh", recursively: true) else{ return } node.position=new_pos arscn_view.scene.rootNode.addChildNode(node) The nodes are well positioned on the plane, in front of the camera. But they are all looking in the same direction. I guess I should rotate the SCNNode but I didn't manage to do this. SCNNode ...

UITabBarContoller, disappears last item from time to time

UITabBarContoller, disappears last item from time to time I have my custom TabBarController as usual, which contains 8 viewController . TabBarController viewController class STTabBarController: UITabBarController,UITabBarControllerDelegate { let tabBarOrderKey = "tabBarOrderKey" private var messangerNavigationController: UINavigationController! override func viewDidLoad() { super.viewDidLoad() self.delegate = self configureViewControllers() setUpTabBarItemTags() getSavedTabBarItemsOrder() } func configureViewControllers() { let clientsController = STClientsViewController(nibName: "STClientsViewController", bundle: nil) let clientNavigationController = UINavigationController(rootViewController: clientsController) clientsController.title = "Clients" clientNavigationController.tabBarItem.image = UIImage(named: "Client") let openHouseController = STOpenHouseViewController(nibName: "STOpenHouseViewControll...

Open window from menu

Open window from menu How can I open new window from my Xib file in Swift2? I've created new NSWindowController + xib, but I can't find how to open it? @IBAction func openPreferences(sender: NSMenuItem) { let wc = SettingsViewController() //... } you have to call showWindow on the new windowController. Also mind that you need to have strong reference to your windowController (if not the object will disappear at the end of method). You can have weak one if you have link from XIB (there is an option not to display window at launch). – Marek H Oct 2 '15 at 19:17 2 Answers 2 I've decided to use custom Storyboard instead of Xib with NSView. So here my code. AppDelegate.swift: class AppDelegate: NSObject, NSAppli...

Xcode/Swift 'filename used twice' build error

Image
Xcode/Swift 'filename used twice' build error I'm new to Swift and am struggling with an error after I have (possibly) correctly installed a 3rd party framework via CocoaPods. The error is as follows. <unknown>:0: error: filename "MainController.swift" used twice: '/Users/myname/Desktop/ProjectName/ProjectName/Controllers/MainController.swift' and '/Users/myname/Desktop/ProjectName/ProjectName/Controllers/MainController.swift' <unknown>:0: note: filenames are used to distinguish private declarations with the same name Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1 As far as I can gather from other forums and seemingly obvious is that I have to remove one of the files being used twice. However I can't see where they would be installed twice. If I remove the file from the /Controllers folder the error becomes 'file not found' etc. So my question is,...

UIBARBUTTON back action

UIBARBUTTON back action let backButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: Selector(("HomeTabController"))) self.navigationItem.leftBarButtonItem = backButton The above code is the creation of button in navigationController but I can create a button cannot write a specific view controller to open. navigationController I have tried with popViewController and popToRootViewController action, need a specific code for opening a particular viewController in swift, with the help of the particular viewController storyboard id and viewcontrollername. popViewController popToRootViewController viewController viewController 2 Answers 2 You need to add func name in #selctor() (Swift 4 version) #selctor() let backButton = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(goToViewController(_:))) s...

How do I call a different function for each TextField in a UITableView (Swift)?

How do I call a different function for each TextField in a UITableView (Swift)? I have a UITableView and my prototype cell consists of a label and a TextField. I also have a class MyClass that contains functions func1, func2, fun3, ... I have several ViewControllers that use the same tableViewCell prototype. Each viewController will have an instance of MyClass, called inst1, inst2, and inst3. When I enter text into FirstViewController's TableView I want each row to call a function from the instance of MyClass that corresponds to the row. So when I enter text into row 1 on the FirstViewController I want to pass the data entered into the textField into func1 of inst1. When data is entered into row 2 of FirstViewController I want the data in the textfield to be passed into func2 of inst1. And so on and so forth down the rows. I am very new to this and would really appreciate some help figuring out how to do this. Let me know if that doesn't make sense and I can try to rephrase it....

IBM Watson Visual Recognition API Key fail - Xcode Swift

IBM Watson Visual Recognition API Key fail - Xcode Swift I'm trying to connect to Watson using VisualRecognitionV3.framework. The framework's compiled fine (via Carthage), and I think I've got the Service Credentials configured correctly, but when I compile Xcode to the simulator I get an invalid-api-key error. Has anyone experienced the same issues? What am I doing wrong? private let apiKey = "Xn5DUtQU8WzgFTL9qNEFwBjxxxxxxxxxxxxxxxxxx" private let classifierId = "DefaultCustomModel_2051029379" private let version = "2018-07-01" var visualRecognition: VisualRecognition! override func viewDidLoad() { super.viewDidLoad() self.visualRecognition = VisualRecognition(apiKey: apiKey, version: version) } override func viewDidAppear(_ animated: Bool) { let localModels = try? visualRecognition.listLocalModels() if let models = localModels, models.contains(self.classifierId) { print(...

Populating UICollection with images via Core Data get blank cell image

Image
Populating UICollection with images via Core Data get blank cell image Hi I currently have the following flow: UIImagePickerController Core Data UICollectionView UICollectionView My issue is that I randomly get images loaded and sometimes I dont get any, do I need to set a delay for the view so it can fetch all the images? PictureViewController class PictureViewController: UIViewController { @IBOutlet weak var collectionView: UICollectionView! let reuseIdentifier = "CellIdentifier" var imageObj: [Image] = let appDelegate = UIApplication.shared.delegate as! AppDelegate override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { fetchData() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } func fetchData() { // Setup fetch data let container = appDelegate.persistentContainer let context = container.viewContext let fetchRequest = NSFetchRequest<Image>(entityName: "Image...

prefersStatusBarHidden not updating after calling setNeedsStatusBarAppearanceUpdate()

prefersStatusBarHidden not updating after calling setNeedsStatusBarAppearanceUpdate() Different vcs inside my app show the status bar visible and others are hidden. This is set to YES in the info.pList "View controller-based status bar appearance": YES // also tried togging this between yes and no "Status bar is initially hidden": YES The app has 2 windows, the main window and a second window. The second window gets presented it front of the main window on a button push. The vc in the second window has the status bar hidden. The problem is if I'm on a vc (mainVC) inside the main window that shows the status bar, I press the button to show the second window, mainVC's status bar disappears. The second window gets presented and after I dismiss it I send a notification to mainVC to call setNeedsStatusBarAppearanceUpdate() but prefersStatusBarHidden isn't triggered so the status bar stays hidden even though it shouldn't be. I even subclassed a Naviga...

Parse JSON in Swift 24hours of problems

Parse JSON in Swift 24hours of problems I am really struggling to parse a json file into my iOS app in Swift. I have a JSOn output from an SQL db. I think the formatting is wrong and the data headers are a bit ambiguous but my developer who I hired to create the process is happy with the output. Link below. So in the last 3 days I have read all of the Apple Developer materials on parsing JSON, also watched numerous tutorials which all cover pretty much the same data, and I don't know how much I have read and converted into actual projects which have all failed. I am really needing some guidance here. I have even in a desperate attempt to understand my problem from a different perspective I have looked at how it is done in other languages. This is the latest iteration: func flightData()-> [[String: String]]{ let url = URL(string: "http://35.237.114.234/api/index.php?uid=Bx7faf08A9fYJ7bZCNMUX9EzxYN2") guard let jsonFileURL = Bundle.main.url(forResource: "jso...