XCode and Swift files for version control - swift

So I have a .gitignore created, which I have basic files included in there, but when it comes to a Swift and .xcodeproj project..
Which one of these files are the only ones that I need inside Github?

Actually, you need both .pbxproj and .xcworkspace, however, it depends:
.pbxproj file contains metadata, file references, configuration... which use to execute/build the project.
.xcworkspace contains and manages subprojects. A common scenario is using cocoapods. If you're developing a small project that's don't need to depend on any 3rd parties, you don't have to create xcworkspace.
xcuserdata folder is safe to ignore. It contains some temporary info like user state, files opened, folders opened.

Related

How to compile any swift file in a given folder?

I use actual folders for my Xcode projects containing my .swift files. I dragged the folder into Xcode but it appears that my swift classes are not being built. I went to my target, went to Build Phase, went to Compile Source and added the missing folder to the references to be built.
My swift files are still not being built.
Which flag could I add to the folder (in Compile Source) for force it to compile every .swift files within it (including the ones in subfolders) ?
I couldn't find any info about it so far, any ideas ?
TLDR Use Groups, not Folder References.
Folder References in Xcode are made mainly for resources. When you create a folder reference, Xcode won't care about the contents. They are helpful when copying resources that should keep their directory structure.
To organize source code files, you need Groups. Groups are logical project folders and most of the time they are backed up by a file system folder anyway.
See also Difference between folder and group in Xcode?

Custom folder structure for Swift Package

When you generate a new Swift project with swift init, you get a Sources folder similar to this. Wondering if there is a way to change the folder structure so it is like this:
main.swift
lib
lib/something.swift
And just get rid of the Sources directory.
I believe that you can use any folder structure that you want. The only thing in that references specific folders in that particular link you provided was the path in the Package.swift file. Which if you want to use, you can just update the path.
The project file keeps track of what swift files have been added into the project and which should be compiled and included in the resulting binary. As long as the files have been added via xcode you should be fine.

Is it save to ignore *pbx* files in version control of xcode project?

I want to upload my xcode project to git, but only needed files. I see different files that i'm sure are created during build, but about others i'm not. I'm talking about *pbx* and *.oa files.
I'm using git. And want to configure an "exclude" file with patterns of files to be ignored. Is it safe to add the following patterns: *pbx* and *.oa?
Maybe someone can share an exclude file..
When using Git, I use the following .gitignore file:
.DS_Store
build/
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
That's for Xcode 3.x. There may be additional files generated by Xcode 4 that should be ignored (maybe someone else will kindly provide that information).
No it is not safe for pbx because project.pbxproject is very important (and a real pain with version control). I am unsure about *.oa but here is a list of items I currently exclude in svn.
*.pbxuser,
*.mode*,
build,
.DS_Store,
*.perspectivev*,
*.xcworkspace,
xcuserdata

Reconfiguring a dynamic library

I'm working with an open source library that's made available as a git repository (XML-RPC) and I'd like to use it in an iPad application. As I understand it, iOS applications should use static libraries for their linking.
Since this comes as a dynamic library, how can I convert it to something I can link with my app and use?
Maybe naive answer but why not just add all the relevent files in the repository to your app and just build it?
Put the files in a seperate folder obviously so you can update them to a newer version if you need to etc. Lots of projects I've done have an 'external' folder that just contains codethat I use from 3rd party sources. I've usually got the source so just compile it into my app and don't bother with making it a library.
Or are there tricky conditions that need to be met to compile this code?
I ended up doing this in several steps:
First, I opened the library project in Xcode and created a new target for the static library. I then made a directory in the project folder called "XMLRPC" and moved all the header files to it. I deleted the now-red invalid references to the header files, and re-added them (but kept the box for copying them to the current folder unchecked).
I added this Xcode project to my main project with a relative reference. I opened my main app's target and added the library project as a direct dependency, and checked the "Always search user paths" option on my main app's target settings.
Lastly, I modified the general Xcode preferences to use a shared build directory. I haven't tried it without that since it was something I wanted anyways; it might not be necessary.
My revision control has two folders in it: one's my project, and the other's the library. The library is still under git control within mercurial; I'm hoping this doesn't cause any issues.

Beginner: Setting up Subversion externals

I believe svn externals is what I want to use but would like some clarification on setting it up. I've never done so.
My environment is:
Mac 10.6.2
Xcode
Cornerstone
Subversion 10.6 (file based/single developer)
Single repository
My svn folder structure is:
\projects\projectA
\projects\projectB
\projects\projectC
\projects\projectX (.lib file)
\projects\projectY (images)
All projects have trunk, tags, and branches folders (just as Subversion suggest). Projects X & Y are really shared code. What I'm wanting to share in them are images and .lib files. For example, projectY will contains PSDs for images plus the product, which is a PNG. projectX will contain Xcode source files plus the product, which is a .lib file.
In projects A thru C, I want to reference the PNG and .lib files and would like to have the option of either referencing latest or a particular version, which I understand externals will do. projectY will contain all of its PNG files. However, projectX will output its .lib to a common build folder that all Xcode projects use.
If I create an external property from projectA to images in projectY, doesn't that mean all of projectY is an external, source code (PSDs) and all? I'm just interested in the PNGs.
Additionally, if I want to reference particular versions of the .lib file in projectX from projects B and C, how is that done since projectX outputs its .lib file to a common Xcode build folder?
When I update an image in projectX, how does projectA get the latest image? Just by doing an update?
If I put all of projectY's images into a product folder and only need three of its say 50 images in projectA, will all 50 still show up in projectA? Is that a performance issue?
You can set an externals reference to any folder in Subversion - you can point to the folder containing the PNGs only. As for particular built versions, you should consider committing the build output, and tagging each version, then setting an svn:externals reference to the tag.
Yes, an upate to projectA will pick up the updated image in projectX via the externals link (as long as you didn't check it out with the option to ignore externals...).
Tagging is quite useful for such scenarios (depending on whether the complexity of your requirements warrants it). The practice I use at work for shared resources is to tag each version (1.0, 1.1, 2.0, etc.) of the code to be distributed via externals, and point the externals at the latest tagged version.
This means that, for whatever reason, should I need to check out an old version of some project, it's always referencing the same shared files, not just the latest revision.