How to include third party code in an Xcode 6 + Swift Project - ios

I want to include some third party code (specifically https://github.com/ortuman/SwiftForms) in my XCode 6 + Swift project. How do I do that?

Very easy :
Download the archive.
Extract it.
Move required files to your project folder
Add the required files to your project.
Clean project
It's done

Simply add the source .swift files to your project, (drag and drop to the file tree on the left hand side of Xcode - you can see the file tree here).
The files you'll need are here.
As stated on the github page: Swift projects is currently not supported by Cocoapods. Until support is available you should just clone the repository and drag the source folder into your project to use SwiftForms.
Once you have the source .swift files presenet in your Xcode project you can create a form as described in the documentation:
"Creating a form using SwiftForms is pretty straightforward. All you need is to derive your controller from FormViewController and define a FormDescriptor instance along with its sections and rows. Here is an example of how to create a simple form to input an email and a user password."
// Create form instace
let form = FormDescriptor()
form.title = "Example form"
// Define first section
let section1 = FormSectionDescriptor()
var row: FormRowDescriptor! = FormRowDescriptor(tag: "name", rowType: .Email, title: "Email")
section1.addRow(row)
row = FormRowDescriptor(tag: "pass", rowType: .Password, title: "Password")
section1.addRow(row)
// Define second section
let section2 = FormSectionDescriptor()
row = FormRowDescriptor(tag: "button", rowType: .Button, title: "Submit")
section2.addRow(row)
form.sections = [section1, section2]
self.form = form

Related

Add file to native target programmatically via tuist/XcodeProj

I am using https://github.com/tuist/XcodeProj in an attempt to add a file to a specific target. Basically I'd like to do the following thing done via ruby mirror using Swift:
require 'xcodeproj'
source_root = '/path/to/xcodeproj'
project = Xcodeproj::Project.open(source_root)
group = project.main_group['TestProject']['TestGroup']
file = group.new_file('TestFile.swift')
target = project.targets.first
target.add_file_references([file])
project.save
So far, I've managed to add the actual file to project but couldn't manage to add it to a specific target:
let sourceRoot = Path("/path/to/xcodeproj")
let project = try XcodeProj(path: sourceRoot)
let target = project.pbxproj.targets(named: "some target name").first!
let group = project.pbxproj.groups.first!
let fileReference = try group.addFile(
at: Path("TestFile.swift"),
sourceTree: .group,
sourceRoot: sourceRoot
)
try project.write(path: Path(sourceRoot))
My question is, how can I add a file reference fileReference added to the project into a specific target programmatically using the library I mentioned above?
Try something like the following (also review Target Object API for details)
try target.sourcesBuildPhase().add(file: fileReference)

How to list all the files that are in TFS GIT repo using REST API

All,
I am trying to get the list of all the files that are in a particular repo in TFS GIT using REST API.
I found the below one but it only display the contents of the specific file name mentioned after "scopePath=/buld.xml", it only display the contents of file build.xml.
But I am trying, only to list all the files that are in a particular repository with out mentioning the particular file name.
Please help me.
https://{accountName}.visualstudio.com/{project}/_apis/git/repositories/{repositoryId}/items?items?scopePath=/&api-version=4.1
You can use the api below:
https://{accountName}.visualstudio.com/{project}/_apis/git/repositories/{repositoryId}/items?recursionLevel=Full&api-version=4.1
Also that could be achieved using VisualStudioOnline libs (at the date of writing comment it becomes AzureDevOps): Microsoft.TeamFoundationServer.Client, Microsoft.VisualStudio.Services.Client.
First, you need to create access token. Then just use code below:
VssBasicCredential credintials = new VssBasicCredential(String.Empty, "YOUR SECRET CODE HERE");
VssConnection connection = new VssConnection(new Uri("https://yourserverurl.visualstudio.com/"), credintials);
GitHttpClient client = connection.GetClient<GitHttpClient>();
List<GitRepository> repositories = await client.GetRepositoriesAsync(true); // or use GetRepositoryAsync()
var repo = repositories.FirstOrDefault(r => r.Name == "Some.Repo.Name");
GitVersionDescriptor descriptor = new GitVersionDescriptor()
{
VersionType = GitVersionType.Branch,
Version = "develop",
VersionOptions = GitVersionOptions.None
};
List<GitItem> items = await client.GetItemsAsync(repo.Id, scopePath: "/", recursionLevel: VersionControlRecursionType.Full, versionDescriptor: descriptor);
Under the hood it's using the REST API. So if you try the same effect using c# lang, better delegate it to lib.
You need to call the items endpoint first, which gives you an objectId (the gitObjectType should be "tree"):
http://{tfsURL}/tfs/{collectionId}/{teamProjectId}/_apis/git/repositories/{repositoryId}/items?recursionLevel=Full&api-version=4.1
Then call the trees end point to list the objects in the tree:
http://{tfsURL}/tfs/{collectionId}/{teamProjectId}/_apis/git/repositories/{repositoryId}/trees/{objectId}?api-version=4.1
test

How to use Crystal Report in FsXaml

I have added Report.rpt and a Report.fs file by right clicking on project in Solution Explorer. In Report.fs I have declared two Type Report() and CachedReport(), which in C# are generated automatically, and added F# code in it by looking at a .cs file which CrystalReport generated in a C# WPF Projet. In Xaml I have
<ContentControl Content="{Binding ShowReport}"/>
<Button Command="{Binding ViewReport}" Content="Click" Grid.Row="1"/>
and in ViewModel
let doc = new CrystalReportsViewer()
let setSource() =
let rpt = new Report()
rpt.Load("~/Report.rpt")
doc.ViewerCore.ReportSource <- rpt
member x.ShowReport = doc
member x.ViewReport = self.Factory.CommandSync(setSource)
When I start the application I can see CrystalReport Viewer in place. If I click the button Application closes automatically.
If I double click on Report.rpt a dialog box pops up and says This document could not be opened.
How can I use it in F# WPF?
Is there any other reporting tool for F# WPF?
I just need to build a C# Class Library with a Report as embedded resource, add the assembly in F# reference and write ...
let doc = new CrystalReportsViewer()
let setSource() =
let rpt = new MyCsClass.CrystalReport1()
....
doc.ViewerCore.ReportSource <- rpt
thats all!

how to create project hierarchical view in pyqt inside main window

I'm trying to implement a project structure viewer to view the structure of a specific programming language. and this project structure view should look like a the tree widget in PyQT , like project explorer in Eclipse.
Example:
if my code is :
rule Adzok
{
meta:
author = " Kevin Breen <kevin#techanarchy.net>"
Description = "Adzok Rat"
Versions = "Free 1.0.0.3,"
strings:
$a1 = "config.xmlPK"
$a2 = "key.classPK"
$a3 = "svd$1.classPK"
condition:
7 of ($a*)
}
Check the figure below.

How to internationalize the UITextField placeholder property value string in interface builder itself?

How can we internationalize the placeholder property's value of a UITextField in interface builder-attribute inspector?
You can easily change it without writing any code.
here is the example in your localized strings file set your placeholder as follows
"itw-s8-fkt.placeholder" = "YOUR TEXT";
You do the same localization as usual:
myTextField.placeholder = NSLocalizedString(#"emptyUsername",
#"userNameTextFieldPlaceholder");
Then you enter the according string in your localizable strings file.
The question has been discussed here, too:
How to use NSLocalizedString in IB [iPhone SDK]?
Describing an alternative, using several xib files.
What I've done, to minimise the amount of localisation boilerplate, is follow the model outlined here (GitHub here): create Interface Builder-friendly helper extensions (#IBInspectable vars, in a single file for convenience) for all the types of controls I want localised, including one for UITextField placeholders. I can then centralise all localisations to a single .strings file for each language and hook them up via IB. The only downside is remembering to add the keys when I create the controls. Localisation debugging (set by editing the Run scheme; I run the app in a non-base language by default) helps spot these early.
I have a single Excel spreadsheet containing keys and translations that gets passed to local translators to update, and a script that (re)generates the .strings files from the .csv prior to release.
With reference to the linked tutorial, my UITextField extension looks like this:
extension UITextField: XIBLocalizable {
#IBInspectable var xibLocKey: String? {
get { return nil }
set(key) {
text = key?.localized
}
}
#IBInspectable var xibPlaceholder: String? {
get { return nil }
set(key) {
placeholder = key?.localized
}
}
}
(The linked GitHub has an almost identical version I've only just spotted). Worth noting that when adding a new localisation I have to manually delete the contents of the XCode autogenerated .strings file, while leaving the file in place, to ensure the extensions get called.

Resources