I have a styles.less file that imports a variables.less file.
For theming purposes, I would like to have a theme.less file, which overrides the variables of variables.less.
My styles.less would look like
#import 'variables';
#import 'theme';
.my-class {
background: #bg;
}
The issue comes when the theme.less file doesn't exist (i.e. if I do not want to apply any theme), since LESS exists the compilation process after throwing the error.
Is there a way to make less throw a warning if the file doesn't exist and continue compiling?
Try this:
#import (optional) "foo.less";
font: http://lesscss.org/features/#import-directives-feature
Related
How to exclude UnityEditor reference from asmdef?
Why I need it:
I have an asmdef file. For example, it is MyAssembly/MyAssembly.asmdef. The MyAssembly contains a lot of features and each feature staff is placed in its own folder. And some of these features has a code that is needed only in editor, and it refers to UnityEditor namespace. Such editor code is placed into an Editor folder.
But as you know, Editor folder name means nothing in terms of asmdef usage. So I add AssemblyDefenitionReference in each folder and refer it to the MyAssemblyEditor.asmdef assembly definition. So the paths looks like this:
MyAssembly/MyAssembly.asmdef
MyAssembly/Editor/MyAssemblyEditor.asmdef - this folder contains no code. It's needed just to place asmdef, because it's not allowed to place two asmdefs in a single folder.
MyAssembly/SomeFeature/Editor/*feature editor staff*
MyAssembly/SomeFeature/Editor/Editor.asmref - refers to MyAssemblyEditor.asmdef
MyAssembly/SomeFeature/*feature staff*
All this works good. But the problem is that, when some developer adds a new feature, he can forget to add a reference to the MyAssemblyEditor.asmdef in the editor folder. And there are no any errors will be shown in this case. This mistake will be revealed only when the build will be cooked. But I'd like that using of UnityEditor in MyAssembly will be instantly marked as an error.
Feel free to suggest other solution for this problem.
This thread got me thinking I can use CsprojPostprocessor to remove all references to UnityEditor from my csproj file. I wrote such class:
using System.Text.RegularExpressions;
using UnityEditor;
// ReSharper disable once CheckNamespace
public class CsprojPostprocessor : AssetPostprocessor
{
public static string OnGeneratedCSProject(string path, string content)
{
if (!path.EndsWith("Editor.csproj") && !path.EndsWith("Tests.csproj"))
{
var newContent =
Regex.Replace(content, "<Reference Include=\"UnityEditor(.|\n)*?</Reference>", "");
return newContent;
}
return content;
}
}
It also can be done with an xml parser or something.
The only thing, that confuse me is that this mechanism is badly documented and doesn't look like something simple users should use. So I use it at my own risk, but looks like there is no guarantee it will be strongly supported in future.
I have a sample Swift Package Manager package (let's call it TestPackage), that is structured in the following way:
TestPackage/
Sources/
TestPackage/
Services/
Services.h
Services.m
TestPackageUI/
UIComponent1.h
UIComponent1.m
UIComponent2.h
UIComponent2.m
include/
TestPackage.h (umbrella header)
The contents of my TestPackage.h look something like this:
/// Umbrella header
/// Services
#import "Services.h" // (or "Services/Services.h")
/// TestPackageUI
#import "Component1.h" // (or "TestPackageUI/Component1.h")
#import "Component2.h" // (or "TestPackageUI/Component2.h")
What I want is that users of this package can do import this package into objc/swift and use the Services and TestPackageUI. They could do something such as:
Objective-C:
#import TestPackage;
/// or
#import <TestPackage.h>
Swift:
import TestPackage
The SPM Usage documentation says:
In case of complicated include layouts or headers that are not compatible with modules, a custom module.modulemap can be provided in the include directory.
So I added a module.modulemap in the include directory with the following content:
module TestPackage {
header "TestPackage.h"
export *
}
But when I try to use this package, the umbrella header TestPackage.h cannot find the header files it includes. Note that these sub-directories are added as headerSearchPaths in the C Settings of the target. I would like to maintain the same project structure. Can anyone help with the correct way to write a modulemap that works with this layout? Thanks in advance.
I am trying to import multiple scss files into my Vue2 project however I am getting errors on compilation - I suspect this is possible, its just my implementation is wrong...
My 'main.scss' file is imported into 'index.js' using the following line:
import './styles/main.scss'
Then, in my 'main.scss' file I have the following:
#import "./base.scss";// color pallete
#import "./variants.scss"; //variant colors using primary colors from base.scss
'base.scss' looks like the following:
$slim-color-brand-orange: #e87820;
$slim-color-brand-blue: #004a79;
$slim-color-brand-charcoal: #595a59;
'variants.scss' looks like the following:
$slim-color-brand-orange-light: lighten($slim-color-brand-orange, 15%);
$slim-color-brand-blue-light: lighten($slim-color-brand-blue, 15%);
$slim-color-brand-charcoal-light: lighten($slim-color-brand-charcoal, 15%);
However the error that I receive looks like the following:
Undefined variable: "$slim-color-brand-light-blue-l5"
Below is an example of how I use the variables:
background-color: $color-error-background;
Can anybody tell me what I am doing wrong? - Thanks in advance ;)
This should work as long as your background-color: $color-error-background is in your main.scss file, after the import statement.
Base and Variants contains variables. Any scss file that imports them, will be able to access those variables.
I think the issue may be the import into index.js.
I've never messed with iOS so this is all new to me. I'm trying to import SQLClient into an an existing Xcode project. (I need to fire off an INSERT from the iOS app.)
https://github.com/martinrybak/SQLClient
I've tried both installation methods listed by Martin via cocoapods and manual but I can't get either to work.
For option #1) everything worked fine until I tried pod install and was met with
Analyzing dependencies
[!] The dependency SQLClient (~> 0.1.3) is not used in any concrete target.
I was expecting the command to produce a file named SQLClient.xcworkspace. I wasn't sure if this new xcworkspace file was meant to replace my main project xcode file. But since it didn't work, I moved onto option #2.
For option #2 I wasn't sure where to put the contents. (Does Martin mean /SQLClient/SQLClient/SQLClient/SQLClient or /SQLClient/SQLClient/SQLClient?)
Was I supposed to copy just the files or the whole folder?
Do the contents go into my project at the same level as my original xcode project file or in a subfolder?
I've tried a couple variations but I admittedly don't know where the SQLClient files/folders should be placed in relation to my other project files.
I've tried messing with my bridge file as well but I've been unable to properly load it.
I have some time (2 days) to figure this out so I'm willing to learn but I need some guidance.
Here's a pic of my existing Xcode project and latest attempt to import SQLClient.
It looks like you have all the files in your project correctly.
Things to check.
If you said yes to create the bridge file when you dragged the object-c file into the project then you just need to add #import "SQLClient.h" to the bridge file. If you created the bridge file manually make sure it is added to Build Settings - Objective-C Bridging Header.
Make sure in your target - general - linked framework and libraries you have libiconv.tb and libfreetds.a
Swift 3
class testViewController: UIViewController, SQLClientDelegate {
// Handles errors from the SQLClient
func error(_ error: String!, code: Int32, severity: Int32) {
print("\(error!) \(code) \(severity)")
}
//MARK: Lifecyle
override func viewDidLoad() {
super.viewDidLoad()
let client = SQLClient.sharedInstance()!
client.delegate = self
client.connect("ServerNameOrIP", username: "cool", password: "cool", database: "database") { success in
client.execute("SELECT * FROM table", completion: { (_ results: ([Any]?)) in
for table in results as! [[[String:AnyObject]]] {
for row in table {
for (columnName, value) in row {
print("\(columnName) = \(value)")
}
}
}
client.disconnect()
})
}
}
}
Created a sample project here
I was able to get installation option #1 working after changing the pod file to include a target.
target "TargetName" do
pod 'SQLClient', '~> 0.1.3'
end
I downloaded SQLClient manually and it worked for me.You will get the steps to connect from swift project from here - https://github.com/salmasumona/Call-SP-from-iOS-project-using-SQLClient
SWIFT 5
enter image description hereThe best way to use Obj-C in a Swift project is to use a bridging header file, what I did with SQLCLient was to drag and drop the files from SQL client and then Xcode will ask if you want to create a bridging header file, select yes.
Inside the bridging header file, import "SQLClient.h", from here you can build the project and everything should compile. You can then create a SQLClient object like you did above and inside the .connect you make the sure the completion handler checks if it was successful then inside the closure you can call client.execute and from here if you put a SQL command as a string and use data as a variable inside the .execute completion block, if you print this data variable you will return all of the data from the SQL Server. It returns in JSON, so from here you can convert using JSON Serialization.
If you have any questions, please feel free to message me and I will return a screenshot of what my code looked like so that it may help you!
I'm trying to create a mixed ObjC-Swift framework. But I'm losing a lot of hairs trying to make a private module for my Swift files.
I followed some steps in iOS mixed dynamic framework - bridge objc headers with private module combined with some steps in https://stackoverflow.com/a/36878037/749438
Basically I have a module.modulemap now which has the following content:
module MyCore { //Adding 'framework' before module is giving me an "Umbrella not found"-error :/
umbrella header "MyCore.h"
export *
module * { export * }
explicit module MyCorePrivate {
header "MyCore_PrivateUmbrella.h"
export *
}
}
The MyCore_PrivateUmbrella.h imports all headers I want to privately expose to my Swift code. The reason behind it is just that it's easier to include 1 header in the module then all the to-be-exposed headers (since you need to include the specific paths to the headers...).
My build settings look like:
DEFINES_MODULE: YES
PRODUCT_MODULE_NAME: MyCore
CLANG_ENABLE_MODULES: YES
SWIFT_OBJC_INTERFACE_HEADER_NAME: MyCore-Swift.h
SWIFT_INCLUDE_PATHS: path to the directory of the module.modulemap
and last but not least; ALWAYS_SEARCH_USER_PATHS is set to NO
In my Swift files I import the module using import MyCore.MyCorePrivate. This works as expected and I can use my code from Objective-C.
Building the project gives me an error like this (the black bars only hide the project name and path to the file):
Now clicking the error brings me to the generated MyCore-Swift.h where the #import MyCore.MyCorePrivate is seemingly wrong.
I've got no idea as of why it's wrong, neither do I know how to fix this. Especially since it's a file generated by XCode.
Does anyone knows what's going down here?
You will need to modify the resulting framework after building it:
1) Don't create any private modules. Revert back to default settings.
2) Any code you want to expose to swift add to your framework header and make sure the headers are set as public in the build section or else swift code wont have access. (Use the <> syntax)
3) Any code from swift to objc make public.
4) Compile you project
5) go to your framework build directory (i.e MyFramework.framework)
6) open the framework header file in the headers directory of the framework (Myframework.h file)
7) Delete all the import statements that should have been private from the framework header
8) Delete all the .h files for the headers that should have been private from the headers directory ( you removed the import statements from the main framework header)
9) go to the .module file and remove the swift modules section
The module file should be very bare bones:
framework module MyFramework {
umbrella header "MyFramework.h" export * module * {export *}}