In an Xcode project, files in the left Project Navigator can be organized into virtual (and actual) folders (Groups).
In Playground, while a new folder can be added, it does not seems to be possible to do the same.
Can it be done in Playground?
And if you can't, what would be similar?
You can create an Xcode Project with a built in Playground, information found here
In Xcode, File -> New -> Project… and then iOS -> Application -> Single View Application
File -> Save as Workspace… Save it as SuperProject.xcworkspace in the same directory as SuperProject.xcproject file.
File -> New -> File… and then iOS -> Source -> Playground. Call it SuperProject.playground, use the same directory as SuperProject.xcproject, and select the top-level “SuperPlayground” under Group (this is not the default option).
File -> New -> Target… and then iOS -> Framework & Library -> Cocoa Touch Framework. Name it SuperPlaygroundiOS and uncheck Unit Tests.
Optional: Control-click on ViewController.swift in the Project Navigator1 and click New File… and then iOS -> Source -> Swift File. Call it SuperClass.swift and make sure SuperProject and SuperProjectiOS are checked under Targets. Replace the contents of this file with this:
import Foundation
class SuperClass{
func greetMe() -> String{
return "Hello"
}
}
Select the framework target (SuperPlaygroundiOS) in the File Inspector for any other files you want to access from your new playground.
Select SuperPlaygroundiOS > iPhone 6S Plus beside the Play/Stop buttons, then Product -> Build.
In SuperProject.playground, type the following at the top of the file:
#testable import SuperPlaygroundiOS
If you did step #5, you can now type this at the bottom of the file too.
SuperClass.greetMe()
Related
I have created new Cocoa Touch Static Library in XCode.
I have written code in: StaticLibrary.m:
#import "StaticLibrary.h"
#implementation StaticLibrary
- (int)addX:(int)x toY:(int)y
{
int sum = x + y;
return sum;
}
#end
I have build project in Release-iphoneos and Release-iphonesimulator, then use terminal:
lipo -create Release-iphoneos/StaticLibrary.a Release-iphonesimulator/StaticLibrary.a -output StaticLibraryFat.a
Now I have fat library "StaticLibraryFat.a". Then I create new iOS Binding Library (Xamarin), click PPM -> Add Existing item -> StaticLibraryFat.a. So the file was added and the new libStaticLibraryFinal.linkwith.cs was created. Code inside:
using System;
using ObjCRuntime;
[assembly: LinkWith ("libStaticLibraryFinal.a", LinkTarget.Simulator, ForceLoad = true)]
I go to Mac, open terminal and use Objective Sharpie:
sharpie bind --output=StaticLibrary --namespace=StaticLibrary ~/Desktop/StaticLibrary/StaticLibrary/*.h --sdk=iphoneos12.1 -scope ~/Desktop/StaticLibrary
Now I copy content of ApiDefinitions.cs into iOS Binding Library (Xamarin) - to ApiDefinitions.cs in project.
ApiDefinition.cs
namespace NativeLibrary
{
[BaseType(typeof(NSObject))]
interface StaticLibrary
{
[Export("addX:toY:")]
int AddX(int x, int y);
}
}
I build iOS Binding Library (Xamarin). In folder bin -> Debug there is NativeLibrary.dll.
I create new iOS App (Xamarin). PPM -> Add Reference -> Project -> Solution -> iOS Binding Library (Xamarin).
In ViewController.cs I write:
using NativeLibrary
and
NativeLibrary.AddX(1, 2);
but there is an error
"Using directive is unnecessary. The type or namespace name "Native
Library" could not be found (are you missing a using directive or an
assembly reference?)
What am I doing wrong?
When I add reference to iOS Class library then the reference is working perfectly. Why reference to iOS Binding Library is not working?
Ok, I have solved it. There was a problem with different namespaces, so Visual Studio can not connect everything. Namespace at ApiDefinition.cs and Structs.cs must be the same as name of iOSBindingLibrary. The generated .dll file has name "NativeLibrary.dll" and I change it to namespace.dll, then at iOS application I add reference to this dll. then using directive (using "namespace"). In class I write name of XCode's library and create new object. Everything is working perfectly.
This is Crazy, but in my case,
just create the ios binding project in a different solution and add the binding project DLL directly in the ios project. it will work fine.
I am integrating crashlytics for android and ios apps for android using build flavor we can give separate organization key but in ios debug and release scheme i need to run different script because i need to provide different keys to that project.
script
"${PROJECT_DIR}/Fabric.framework/run" 834343231341432432432432432408497cdbfa13ceb728b296e1c595557bb8c389a33693f150f
There's many options for build confg in iOS as well depending on your project.
You could use configuration files :
xcconfig
1 : Create a new xcconfig file ( base.xcconfig) with the following :
KEY = YOUR_DEBUG_KEY
2 : Create a release config file ( release.xcconfig) :
KEY = YOUR_LIVE_KEY
3 : Set the newly created files in project settings :
4 : In the Build Phase :
"${PROJECT_DIR}/Fabric.framework/run" ${KEY}
Another simple way to do it ( if something needs to be changed in the code itself) :
#ifdef DEBUG
// debug config
#else
// release config
#endif
You can edit your sheme to add a script for each configuration.
EDIT: You click on your scheme -> Edit Scheme... -> Click on Build Arrow -> Pre/Post actions -> + -> New Run Script Action
I'd like to be able to inflate/deflate Swift3 Data structs. I found GzipSwift, but it's not clear how I make that available to my iOS app. The naive things I've tried include:
Copying the Data+Gzip.swift file into my own project. This then complains about the import zlib at the top of said file. I think that has something to do the with the modulemap files in the zlib directory of the same sources. But I'm not sure what or how to recreate those in my own project.
Cloned the repository from github, opened XCode and built in (pressed the run button basically). Then tried to add that as a linked library or framework to my own project. I'm pretty sure just selecting the top level directory of the repository is not what I want to do, but I didn't know what else to try.
I've found some other code out there, but it seems dated and relative to Swift2.
Swift 5 implementation using Compression.
Took me a few days to realise I had to drop the first 2 bytes of the compressed data.
Hope it can help somebody else.
import Foundation
import Compression
func decompress(_ data: Data) -> String {
let size = 8_000_000
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: size)
let result = data.subdata(in: 2 ..< data.count).withUnsafeBytes ({
let read = compression_decode_buffer(buffer, size, $0.baseAddress!.bindMemory(to: UInt8.self, capacity: 1),
data.count - 2, nil, COMPRESSION_ZLIB)
return String(decoding: Data(bytes: buffer, count:read), as: UTF8.self)
}) as String
buffer.deallocate()
return result
}
I just recently had to add that exact library and file to my project, and after a lot of troubleshooting finally got it working, so let me walk you through the steps!
Okay
1) Go to the top level directory of your project in finder, and create a new folder called Swiftzlib or whatever you want the name of the module that you will be importing to be. (What we will do is add the zlib library as a module, so think of it as importing Foundation or some such other module). To clarify, this Swiftzlib directory will end up as a child directory of the same directory that contains your *.xcodeproj and *.xcworkspace files.
2) Inside the folder you created, make two files.
include.h
module.modulemap
3) In your include.h file, enter the following:
#include<zlib.h>
4) In your module.modulemap file, enter the following:
module Swiftzlib [system] {
header "include.h"
export *
}
Where Swiftzlib is the same as the name of the folder that you created.
5) Open your Xcode project, and select your target
5a) In Build Phases -> Link Binary with Libraries, add libz.tbd
5b) In Build Settings -> Swift Compiler - Search Paths, add $(PROJECT_DIR)/Swiftzlib non-recursively to the import paths
5c) In Build Settings -> Other Linker Flags, add -lz as a flag
6) Select your project in Xcode (may not be necessary, but I've done it in my project and it works)
6a) In Build Settings -> Swift Compiler - Search Paths, add $(PROJECT_DIR)/Swiftzlib non-recursively to the import paths
7) In Data+Gzip.swfit, add import Swiftzlib to the top of the file
8) Clean, Build, and Run!
I maintain a small Swift 3+ wrapper around Apples native libcompression framework at:
https://github.com/mw99/DataCompression
Usage example for gzip:
let data: Data! = "https://www.ietf.org/rfc/rfc1952.txt".data(using: .utf8)
let gzipped: Data! = data.zip()
let gunzipped: Data? = gzipped.unzip()
assert(data == gunzipped)
But if you are only interested in classic inflate and deflate you may use the .inflate() and .deflate() methods instead. That will save 18 bytes because the gzip header won't be added.
I made a small spm extension inspired by #vauxhall 's answer
https://github.com/mezhevikin/Zlib
import Zlib
// Decompressed data
print(data.decompressed)
// Decompressed string
print(data.decompressedString)
I know that this is not a new question, but I have tried many solution like edit Xcode project file manually or recreating new scheme for target after renaming it.
Can somebody help me with this question how copy target in right way and then rename it.
Right now I just rename scheme and it is displayed as is. But when Xcode is running app, under progress indicator it says: Running ProjectName-copy. But I have renamed target but seems product names or some build settings still has "...-copy" in the name.
Duplicate a target.
Double click the copy of target and change its name to whatever you want.
'New target -> Build Settings -> Packaging -> Product Name', change it to the name you want.
Product (Menu item) > Schemes > Manage Schemes, then click the '+' button, select the new target and click 'OK' button.
All done.
PS:
After Duplicating the target, Xcode make a new Info.plist file named 'xxx copy-Info.plist' in the root path of project. If you want to change its name and path, after doing this, you should go to 'New target -> Build Settings -> Packaging -> Info.plist file' and change the value to the path of new file.
Press on the target name in xcode ( in the same place where you want to select the sim/device type) and select "Manage Schemes...". Highlight the scheme with the copy inside name and press enter on keyboard. You can rename it there.
To copy a target, click on your project, and go to the project inspector tab that looks like this:
Project:
SomeName
Targets:
SomeName
right click on a target, and select duplicate, then double-click slowly on the new target, or select the new target and hit enter, and just put the new name in!
To change running targets, to the top left of your xcode you will see this:
(start button) (stop Button) (target name and device)
[|>] [[]] [/\ TargetName > TargetDevice]
click the target name, next to the little compass (mathematical compass, not navigational) and select your desired target from the dropdown.
Hope I helped, Matroskin.
I have beed using Advance new file package in Sublime Text 2 and when I press shortcut for creating new file is in my main directory C\users\%name\.
Is it possible (or with another package) to set path to be in folder that I'm currently at.
Example, if I'm at
C:\Users\%user\Desktop\Notebook\Ruby programs\Ruby\test.rb
to set the path to
C:\Users\Bane\Desktop\Notebook\Ruby programs\Ruby\
Open Preferences -> Package Settings -> AdvancedNewFile -> Settings - User and add the following to the file.
{"default_root": "current"}
You can see more about settings on the GitHub page.