How to set breakpoints in Xcode for files with obscure file extensions? - xcode

I'm working on a project that uses Rust, so the files have an extension of .rs. Xcode won't let me set breakpoints. It seems it just handles the file as plain text. Is there any way to get it to allow me to set breakpoints in .rs files? One solution is to mark each .rs file as being some type of source code file that Xcode recognizes, e.g. an Objective-C source code file, but I'm looking for something that will apply globally to all .rs files.

Xcode doesn't support Rust, and Rust files are plain text files for Xcode. Xcode debugger is just for C languages (C, C++, Objective-C) and Swift. Declaring .rs files as Objective-C only makes Xcode assume that they are Objective-C code.
You need a Rust IDE for debugging Rust code.

Related

Building a C static library using recent Xcode? Including that in Swift?

Does anyone have a guide to setting up a project that produces a static library under recent versions of Xcode? There are a few for older versions, but they use a project setting called "C/C++ Library" which seems to have been removed.
I notice "External build system" is still in there, and maybe that's a solution? The C code won't be changing structure too much, so a makefile could be a solution - but I've never used this type before, so I'd like to hear from people that have.
Ultimately the C code will be consumed by a Swift/Cocoa application. Am I correct in thinking that I simply include both projects in a workspace, drag the .a and bridging .h into the Swift project, and go?

Is it possible to have Xcode completion in new Swift file edition (not in a project)?

Now that I found out that you can actually execute a swift program in command line by calling swift myScript.swift I was thinking about writing a few programs that I usually write in Python with Swift.
Although I can do that in another editor without trouble, I grew used to Xcode's completion (automatically fill existing class names, methods, constructor parameters, etc. that makes coding much easier). However, when I open a single Swift file in Xcode (without including it in a full project) with File > New... > File... Xcode doesn't do any completion.
Is there a special setup to do? Also, from a single open swift file, is there a way to run the script directly in a terminal from Xcode (and maybe use the debugger, etc.)?
As far as I know, Xcode is pretty useless for writing single independent swift scripts. I feel I'm missing something.
All the information I found was either about how to use the REPL in a terminal (and copy paste from a file written in any other text editor), or using Playgrounds (which are nice but incredibly slow when running simple algorithms that perform some nested loops or such), or of course making a small project, which feels way too much for some simple script writing.
Xcode's code completion and related tools work from knowledge of the compile-time and run-time environment of your code... that knowledge is supplied by the compiler. Xcode doesn't know what a compiler is doing with any given file unless Xcode is the one telling the compiler what to do with that file — i.e. the file is in an Xcode project, which specifies how to compile, or in a playground, which implicitly provides a certain compilation/runtime environment.
You can create an Xcode project for a Command Line Tool (using Swift, even). That'll tell Xcode how to compile it, and thus how to interpret it for code completion and whatnot. And hitting Run in Xcode will use the debugger, with command-line I/O in the Xcode window's debug area.
(And if you're looking for other ways besides playgrounds and projects for Xcode to work with Swift files... they do look at feature requests.)

How to compile swift library project into .so file?

I'm new to XCode and Objective C / Swift. I'm trying to make a Swift library project that doesn't depend on cocoa or anything. So it's just Swift files. What type of project should I be creating (I'm assuming there are multiple ways of doing this? How do I need to configure the project so that it builds to a .so file? And finally, how do I build it to a .so file?
I'm using Xcode6-beta.
You can create a Swift library for iOS by creating a new Xcode Project and selecting iOS/OS X -> Framework & Library -> Cocoa Touch Framework and then setting the language to Swift on the next screen.
Once this project has been created you are not required to link against the Cocoa frameworks, and can remove any references to them if needed.
Upon compiling this project Xcode will create a .framework folder in your build directory which contains a dynamic library which you should then be able to link against. Note however that I haven't had any success myself yet at linking directly against this file, even though it appears to be a standard dynamic library.
In terms of using this shared object file on Android I believe you will be out of luck, as the Swift language (much like Objective-C) requires a runtime library which is simply not available on other platforms at this time.
... I think you are limiting your train of thought a bit or expecting leaps and bounds to quickly swift is ready to work with objective c and cocoa so you aren't going to be able completely avoid cocoa however you wont have to write any of it the compiler will do that for you. but you will still have to use cocoa frameworks or modules like foundation( contains many specialized objects for program development), UIKit, CoreData however these don't require you to write the cocoa. and if Im not mistaken the .so file is made on compile so you never actually touch that file but rather is supporting files .swift
to do it
if your looking to do everything programmatically or if you want to xib or storyboards just make a new project I prefer an empty project.(set programming language to swift and decide if you want core data or not finish the project wizard thing and bam you have a YourAppDelegate.swift you can make another .swift file or a storyboard and hopefully you know what to do from there. Swift book is available on ibooks for free its nicely written
although it will be quite a while before cocoa and swift are completely separate... if ever

Including C++ header files in Objective-C++ when they conflict with Objective-C macros

In Xcode, I've created a "Cocoa application" project. One of its dependencies is a framework containing C++ code. I renamed AppDelegate.m to AppDelegate.mm and included the framework.
The project fails to compile. The problem is that the C++ header files in the framework are using some symbols that conflict with Objective-C or Cocoa.
The C++ header files are defining functions called verify() and check(), which conflict with /usr/include/AssertMacros.h in the MacOSX10.8 SDK.
The C++ header files contain a variable called NO, which conflicts with the Objective-C macro NO.
A workaround would be to modify the C++ code in the framework to avoid these conflicts. But since it's a large C++ project maintained by another organization, this would take time and would possibly break in future updates of the C++ project.
Is there some way just to tell Clang/Xcode to treat those C++ header files as C++ instead of Objective-C++?
Reading through the /usr/include/AssertMacros.h that comes with Mac OS 10.8, it looks like you could do:
#define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
before including AssertMacros.h, which will prevent it from defining macros called verify() and check().
Regarding NO: you could use the preprocessor to rename that variable for you. For example:
#define NO NO_libraryname_renamed
#include <libraryname.hh>
#undef NO
Depending on how the NO variable is used by the library, this might cause problems — if the header is declaring it as extern, then your Cocoa app will refer to it by the wrong name, and you'll get an undefined symbol error. But as long as you're not using that variable, and the library isn't depending on your app to define that variable, then you should be fine.
(And please file a bug report with the offending library, requesting that they rename their variable.)
Mixing several languages is calling for grief. Even more so mixing Objective C++ (itself a strange hybrid) with C++. Don't do it.

Xcode not recognizing c++ syntax

I have a project in xcode where I use a c++ library, it use to work and compile correctly, but whithout any change now it won't compile telling some errors in the .h files libraries and in my view controller where I use some c++ variables, I have my file with the .mm extension and all the errors I'm having are about the c++ syntax like in the word namespace it tells it's Unknown type name or in every other line where the syntax is c++ type Xcode can't recognize it.
Found out by my self on this page http://answers.oreilly.com/topic/631-how-to-get-c-and-objective-c-to-play-nicely-in-xcode/
The problem was that the compiler was making a mess because only the files where I used c++ code I put them the .mm extension and there was some files with just .m
By changing the extension of every file in my project to .mm even if it hasn't any c++ code solved the problem.

Resources