I've tried two ways of doing optional imports but neither seems to be working. Is this possible as of less 2.6.0?
#useRTL: true;
& when (#useRTL = true) {
#import "bi-app/bi-app-rtl.less";
}
#useRTLpath: "bi-app/bi-app-rtl.less";
#import (optional) "#{useRTLpath}";
Related
I understand what the parent selector does but I'm not sure I understand the syntax when it's at the beginning of a line. For example, this can be found in semantic-ui-less. For which use case would you wrap the import statement into & {}
/* Global */
& { #import "definitions/globals/reset"; }
& { #import "definitions/globals/site"; }
Why using this syntax instead of simply stacking the imports? What would the previous syntax do more over this one:
/* Global */
#import "definitions/globals/reset";
#import "definitions/globals/site";
Thanks!
I'm trying to make a setter template which will allow me to use a m prefix for member variables. So when I have a field mTest is should give me a setter: public setTest and not setmTest. I think I have the correct logic, but Character.isUpperCase returns false even if it's a upper case letter. I've added some debugging a bit improvised, since it's kind of weird to test, because IntelliJ check if there is a proper function returned. When generating a setter I get an error dialog where I can see my output of:
#if($Character.isUpperCase($paramName.charAt(1)))
paramIsUppercase: $paramName.charAt(1)
#else
paramIsNotUppercase: $paramName.charAt(1)
#end
Complete code:
#set($paramName = $helper.getParamName($field, $project))
// debugging
#if($Character.isUpperCase($paramName.charAt(1)))
paramIsUppercase: $paramName.charAt(1)
#else
paramIsNotUppercase: $paramName.charAt(1)
#end
#if($StringUtil.startsWith($paramName, 'm') && $Character.isUpperCase($paramName.charAt(1)))
#set($paramName = $paramName.substring(1))
#end
#set($paramName = $StringUtil.decapitalize($paramName))
public ##
#if($field.modifierStatic)
static void ##
#else
$classname ##
#end
set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($paramName))($field.type $paramName) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName;
#if(!$field.modifierStatic)
return this;
#end
}
When using this to create a setter for mTest I get an error for my debugging
paramIsNotUppercase: T
Why is this returning false and is there a fix for this?
It looks like the problem is that $Character is not defined, which means the expression will always return false. There is a way to get around this. It is a horrible hack, but it works for me. Use the following template lines.
## get some object
#set($String='')
## abuse it to obtain the desired jdk class
#set($Character=$String.class.forName('java.lang.Character'))
After that you can use $Character regularly as you desire (i.e. $Character.isUpperCase($paramName.charAt(1))).
However there is no need to create your own setter template if you want to use prefixes for fields. Just go to the settings File | Settings | Editor | Code Style | Java | Code Generation and specify a Name prefix for Field and getters and setters will be generated correctly.
I am trying to integrate the Chartboost IOS SDK with Swift. I have followed all the instructions on the Chartboost IOS Integration page https://answers.chartboost.com/hc/en-us/articles/201220095-iOS-Integration and have created a bridging header to use the framework in my swift project.
BridgingHeader.h
#import <Chartboost/Chartboost.h>
#import <Chartboost/CBNewsfeed.h>
#import <CommonCrypto/CommonDigest.h>
#import <AdSupport/AdSupport.h>
My BridgingHeader.h file is loacated in my project root directory http://i.imgur.com/DcTcixo.png and I have followed the necessary steps to add the BridgingHeader.h to my Build Settings http://i.imgur.com/jvtzs7a.png but when I run the project I get 52 errors like -> http://i.imgur.com/WCvyooz.png. Why am I getting these errors and how do I get rid of them?
It looks like the headers require UIKit and Foundation. Add this line at the top of your bridging header.
#import <UIKit/UIKit.h>
Also, have you made sure your bridging header is in the project's root in the file system? The hierarchy of Xcode's Project Navigator isn't necessarily the same as the file system.
It's looking for the header in /Users/andrew/Documents/dev/ios/Protect Paigridge/ Open finder and make sure that the header is in that directory. Xcode may have created it a level deeper where the rest of your code files are. If that's the case, you can edit entry in Build Settings or move the file.
Adding onto the top answer said above try adding both
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Chartboost/Chartboost.h>
to your BridgingHeader.h File
and make sure they are both above the
#import <Chartboost/Chartboost.h>
as shown above
Swift Chartboost Code, Add it in AppDelegate Class :
func applicationDidBecomeActive(application: UIApplication)
{
let kChartboostAppID = "5472ef8f04b01601a1a5814c";
let kChartboostAppSignature = "5b6222426e68cda48669a1d4d8246d4c3d20db9c";
Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: self);
Chartboost.cacheMoreApps(CBLocationHomeScreen)
}
class func showChartboostAds()
{
Chartboost.showInterstitial(CBLocationHomeScreen);
}
func didFailToLoadInterstitial(location :String!, withError error: CBLoadError)
{
}
func didDismissInterstitial(location :String! )
{
if(location == CBLocationHomeScreen)
{
Chartboost.cacheInterstitial(CBLocationMainMenu)
}
else if(location == CBLocationMainMenu)
{
Chartboost.cacheInterstitial(CBLocationGameOver)
}
else if(location == CBLocationGameOver)
{
Chartboost.cacheInterstitial(CBLocationLevelComplete)
}
else if(location == CBLocationLevelComplete)
{
Chartboost.cacheInterstitial(CBLocationHomeScreen)
}
}
Calling Syntax:
AppDelegate.showChartboostAds()
This issue is how to import.
You can make objC code and bridge.h, to shows in your code
[Chartboost showInterstitial:CBLocationHomeScreen];
For swift
Chartboost.showInterstitial(CBLocationHomeScreen)
i wish that help you
Is there a way to get IntelliJ to be smarter about the getters/setters it generates? In particular, if a field name has underscores in it, can the getter strip them out and convert to CamelCase?
For instance, I would expect the below getter to be getCarneAsada():
public class Taco {
private String carne_asada;
public String getCarne_asada() {
return carne_asada;
}
}
I found the Code Style->Java->Code Generation area, but none of the options seem appropriate...it's not a prefix or a suffix I want to exclude. It's inner underscores.
You can use Live Templates to accomplish this. It will not be accessible from Code Generation but it will still be quite easy to use.
I have created a Main class with the property carne_asada:
Now open up Live Templates in the settings and create a new template called getu under other:
Press the little link called Define at the bottom to define when this template is valid. Then choose Java | Declaration:
Press the button Edit Variables to open a window where each of the live template variables can be defined. Now create the following variables:
VAR : suggestFirstVariableName("Object")
TYPE : typeOfVariable(VAR)
CAP_CAM_VAR : capitalize(underscoresToCamelCase(VAR))
The order is quite important so the VAR must come first. In my example CAP_CAM_VAR stands for Capitalize and CamelCase the VAR variable. Set the Skip if defined according to the image:
Now press OK and OK again to get back to the editor.
Try the new getu live template by typing getu and then press Tab:
Press Enter and the getter generation has finished:
Now if you had had some more variables with underscores you will get a list to choose from so here is an example:
And the result is just beautiful:
You can easily create the same setu live template and maybe some sgetu that creates them both at the same time.
Hope this helps a little bit!
Here are templates for generating getter/setter working under IntelliJ IDEA 2016 and Android Studio 2.2.
Camelized Getter:
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean && $field.primitive)
#if ($StringUtil.startsWithIgnoreCase($name, 'is'))
#set($name = $StringUtil.decapitalize($name))
#else
is##
#end
#else
get##
#end
#set($words = $StringUtil.split($name, "_"))
#set($name = "")
#foreach($word in $words)
#set($name = $name + $StringUtil.capitalize($word))
#end
${name}() {
return $field.name;
}
Camelized Setter:
#set($paramName = $helper.getParamName($field, $project))
#if($field.modifierStatic)
static ##
#end
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#set($words = $StringUtil.split($name, "_"))
#set($name = "")
#foreach($word in $words)
#set($name = $name + $StringUtil.capitalize($word))
#end
void set$name($field.type $StringUtil.decapitalize($name)) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName;
}
If you want fluent getter/setter with above, please refer my gists.
https://gist.github.com/k24/72d0be3d76d4eb987c6d4eb1d8f42db2
I'm working on several iOS projects where I think enumerated datatypes would be helpful to me. For example, I have a game where the player can walk in several directions. I could just define four constants with string values as kDirectionUp, kDirectionDown, etc.
I think an enumerated type would be better here. Is that correct? If so, how do I define an enum here so that I can later compare values? (As in, if(someValue == kDirectionUp){})
That sounds like the right thing to do.
It's really simple to create enums in Objective-C using C-style type definitions. For example, in one of my header files, I have the following type definition:
typedef enum {
CFPosterViewTypePoster = 0,
CFPosterViewTypeStart, // 1
CFPosterViewTypeEnd, // 2
.... // 3
} CFPosterViewType;
You define an object of CFPosterViewType and set it to one of the values:
CFPosterViewType posterType = CFPosterViewTypeStart;
When comparing CFPosterViewType values, it's as simple as doing the following:
if (posterType == CFPosterViewTypePoster) {
// do something
}
Note that the commented out numbers in the enum above are implicit values. If you want to do something differently, say, define a bitmask, or anything else where you need the values to be different than the default, you'll need to explicitly define them.
In a header file, define an enum type, e.g.:
// SomeHeaderFile.h
typedef enum {
MOPlayerDirectionNone,
MOPlayerDirectionUp,
MOPlayerDirectionDown,
…
} MOPlayerDirection;
Whenever you need to use MOPlayerDirection, #import that header file. You can then use it as a type as well as its possible values.
For instance:
#import "SomeHeaderFile.h"
#interface MOPlayer : NSObject {
MOPlayerDirection currentDirection;
}
- (void)moveToDirection:(MOPlayerDirection)direction;
- (void)halt;
#end
and:
#import "SomeHeaderFile.h"
#import "MOPlayer.h"
#implementation MOPlayer
- (id)init {
self = [super init];
if (self) {
currentDirection = MOPlayerDirectionNone;
}
return self;
}
- (void)moveToDirection:(MOPlayerDirection)direction {
currentDirection = direction;
switch (currentDirection) {
case MOPlayerDirectionUp:
// do something
break;
case MOPlayerDirectionDown:
// do something
break;
}
}
- (void)halt {
if (currentDirection != MOPlayerDirectionNone) {
// do something
currentDirection = MOPlayerDirectionNone;
}
}
#end
If an enumeration is tightly related to a class, it’s common to define it in the same header file as the class declaration. In the example above, instead of defining MOPlayerDirection in SomeHeaderFile.h, you could define it in MOPlayer.h instead.
Just define them at the top of your file:
enum // direction types
{
kDirectionUp = 0,
kDirectionDown, // 1
kDirectionLeft, // 2
kDirectionRight // 3
};
then you can call as required:
if(someValue == kDirectionUp){ // do something }