Skip to content

添加 @property (%@, nonatomic) 和 @property (nonatomic, %@) 位置的设置 #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ESJsonFormat/Controller/ESSettingController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ @interface ESSettingController ()
@property (weak) IBOutlet NSButton *btnImpMJExtesion;
@property (weak) IBOutlet NSButton *btnGeneric;
@property (weak) IBOutlet NSButton *btnOutputToFile;
@property (weak) IBOutlet NSButton *btnPropertyPosition;

@end

Expand All @@ -25,10 +26,13 @@ - (void)windowDidLoad {
self.btnImpMJExtesion.state = (NSCellStateValue)[[ESJsonFormatSetting defaultSetting] impOjbClassInArray];
self.btnGeneric.state = (NSCellStateValue)[[ESJsonFormatSetting defaultSetting] useGeneric];
self.btnOutputToFile.state = (NSCellStateValue)[[ESJsonFormatSetting defaultSetting] outputToFiles];
self.btnPropertyPosition.state = (NSCellStateValue)[[ESJsonFormatSetting defaultSetting] propertyPosition];

if (![ESUtils isXcode7AndLater]) {
self.btnGeneric.enabled = NO;
}

[self updateSettingState];
}

- (IBAction)btnImpMtdForMJClick:(NSButton *)sender {
Expand All @@ -47,12 +51,19 @@ - (IBAction)btnUpercaseKeyWordForIdClick:(NSButton *)sender {
[[ESJsonFormatSetting defaultSetting] setUppercaseKeyWordForId:sender.state];
}

- (IBAction)btnPropertyPosition:(NSButton *)sender {
[[ESJsonFormatSetting defaultSetting] setPropertyPosition:sender.state];
[self updateSettingState];
}

- (IBAction)tapGes:(NSClickGestureRecognizer *)sender {
NSURL* url = [[ NSURL alloc ] initWithString :@"http://t.cn/RLarUfg"];
[[NSWorkspace sharedWorkspace] openURL:url];
}


- (void)updateSettingState
{
self.btnPropertyPosition.title = self.btnPropertyPosition.state ? @"@property (%@, nonatomic)" : @"@property (nonatomic, %@)";
}

@end
29 changes: 21 additions & 8 deletions ESJsonFormat/Controller/ESSettingController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
<outlet property="btnGeneric" destination="FIE-dA-b1R" id="Ixf-zt-Ngh"/>
<outlet property="btnImpMJExtesion" destination="dXc-h6-O8R" id="AND-ou-tuH"/>
<outlet property="btnOutputToFile" destination="xTo-NY-de8" id="bJG-th-UpQ"/>
<outlet property="btnPropertyPosition" destination="b3H-Pw-vNv" id="OwM-w5-SA8"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="ESJsonFormat Setting" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<rect key="contentRect" x="760" y="506" width="475" height="141"/>
<rect key="contentRect" x="760" y="506" width="475" height="180"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="-1" width="475" height="141"/>
<rect key="frame" x="0.0" y="1" width="475" height="180"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button translatesAutoresizingMaskIntoConstraints="NO" id="FIE-dA-b1R">
<rect key="frame" x="48" y="76" width="229" height="18"/>
<rect key="frame" x="48" y="115" width="229" height="18"/>
<buttonCell key="cell" type="check" title="Use generic for Xcode 7 and later" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Gb8-hX-fES">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -33,7 +34,7 @@
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="xTo-NY-de8">
<rect key="frame" x="48" y="47" width="134" height="18"/>
<rect key="frame" x="48" y="86" width="134" height="18"/>
<buttonCell key="cell" type="check" title="The output to files" bezelStyle="regularSquare" imagePosition="left" inset="2" id="Qcn-Rz-YgD">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -43,7 +44,7 @@
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="dXc-h6-O8R">
<rect key="frame" x="48" y="105" width="287" height="18"/>
<rect key="frame" x="48" y="144" width="287" height="18"/>
<buttonCell key="cell" type="check" title="Implement method 'objectClassInArray' for" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="5wx-mN-wAc">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -53,7 +54,7 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eB9-TM-LrY">
<rect key="frame" x="336" y="106" width="84" height="17"/>
<rect key="frame" x="336" y="145" width="84" height="17"/>
<gestureRecognizers>
<clickGestureRecognizer delaysPrimaryMouseButtonEvents="YES" numberOfClicksRequired="1" id="L4p-DW-5eC">
<connections>
Expand All @@ -68,7 +69,7 @@
</textFieldCell>
</textField>
<button translatesAutoresizingMaskIntoConstraints="NO" id="Kcy-UJ-T8e">
<rect key="frame" x="48" y="18" width="193" height="18"/>
<rect key="frame" x="48" y="57" width="193" height="18"/>
<buttonCell key="cell" type="check" title="Uppercase key word for 'id'" bezelStyle="regularSquare" imagePosition="left" inset="2" id="d8z-7B-IM8">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
Expand All @@ -77,9 +78,21 @@
<action selector="btnUpercaseKeyWordForIdClick:" target="-2" id="xGN-0o-Xzr"/>
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="b3H-Pw-vNv">
<rect key="frame" x="48" y="28" width="193" height="18"/>
<buttonCell key="cell" type="check" title="@property (%@, nonatomic)" bezelStyle="regularSquare" imagePosition="left" inset="2" id="hDo-I1-gqd">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="btnPropertyPosition:" target="-2" id="gmI-6H-BWi"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="Kcy-UJ-T8e" firstAttribute="top" secondItem="xTo-NY-de8" secondAttribute="bottom" constant="15" id="5yF-5x-qxe"/>
<constraint firstItem="b3H-Pw-vNv" firstAttribute="top" secondItem="Kcy-UJ-T8e" secondAttribute="bottom" constant="15" id="A7d-D5-MP5"/>
<constraint firstItem="dXc-h6-O8R" firstAttribute="leading" secondItem="b3H-Pw-vNv" secondAttribute="leading" id="BZb-qI-g2T"/>
<constraint firstItem="dXc-h6-O8R" firstAttribute="leading" secondItem="FIE-dA-b1R" secondAttribute="leading" id="NAD-BC-D71"/>
<constraint firstItem="xTo-NY-de8" firstAttribute="top" secondItem="FIE-dA-b1R" secondAttribute="bottom" constant="15" id="NlS-iG-40P"/>
<constraint firstItem="dXc-h6-O8R" firstAttribute="leading" secondItem="xTo-NY-de8" secondAttribute="leading" id="OfI-Gs-mcC"/>
Expand All @@ -94,7 +107,7 @@
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="-122.5" y="230.5"/>
<point key="canvasLocation" x="-122.5" y="250"/>
</window>
</objects>
</document>
17 changes: 10 additions & 7 deletions ESJsonFormat/ESJsonFormatManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,22 @@ + (NSString *)parsePropertyContentWithClassInfo:(ESClassInfo *)classInfo{
* @return
*/
+ (NSString *)formatObjcWithKey:(NSString *)key value:(NSObject *)value classInfo:(ESClassInfo *)classInfo{

NSString *propertyFormat = [[ESJsonFormatSetting defaultSetting] propertyPosition] ? @"@property (%@, nonatomic) %@ *%@;" : @"@property (nonatomic, %@) %@ *%@;";

NSString *qualifierStr = @"copy";
NSString *typeStr = @"NSString";
//判断大小写
if ([ESUppercaseKeyWords containsObject:key] && [ESJsonFormatSetting defaultSetting].uppercaseKeyWordForId) {
key = [key uppercaseString];
}
if ([value isKindOfClass:[NSString class]]) {
return [NSString stringWithFormat:@"@property (nonatomic, %@) %@ *%@;",qualifierStr,typeStr,key];
return [NSString stringWithFormat:propertyFormat,qualifierStr,typeStr,key];
}else if([value isKindOfClass:[@(YES) class]]){
//the 'NSCFBoolean' is private subclass of 'NSNumber'
qualifierStr = @"assign";
typeStr = @"BOOL";
return [NSString stringWithFormat:@"@property (nonatomic, %@) %@ %@;",qualifierStr,typeStr,key];
return [NSString stringWithFormat:propertyFormat,qualifierStr,typeStr,key];
}else if([value isKindOfClass:[NSNumber class]]){
qualifierStr = @"assign";
NSString *valueStr = [NSString stringWithFormat:@"%@",value];
Expand All @@ -71,7 +74,7 @@ + (NSString *)formatObjcWithKey:(NSString *)key value:(NSObject *)value classInf
typeStr = @"long long";
}
}
return [NSString stringWithFormat:@"@property (nonatomic, %@) %@ %@;",qualifierStr,typeStr,key];
return [NSString stringWithFormat:propertyFormat,qualifierStr,typeStr,key];
}else if([value isKindOfClass:[NSArray class]]){
NSArray *array = (NSArray *)value;

Expand All @@ -90,19 +93,19 @@ + (NSString *)formatObjcWithKey:(NSString *)key value:(NSObject *)value classInf
qualifierStr = @"strong";
typeStr = @"NSArray";
if ([ESJsonFormatSetting defaultSetting].useGeneric && [ESUtils isXcode7AndLater]) {
return [NSString stringWithFormat:@"@property (nonatomic, %@) %@%@ *%@;",qualifierStr,typeStr,genericTypeStr,key];
return [NSString stringWithFormat:propertyFormat,qualifierStr,typeStr,genericTypeStr,key];
}
return [NSString stringWithFormat:@"@property (nonatomic, %@) %@ *%@;",qualifierStr,typeStr,key];
return [NSString stringWithFormat:propertyFormat,qualifierStr,typeStr,key];
}else if ([value isKindOfClass:[NSDictionary class]]){
qualifierStr = @"strong";
ESClassInfo *childInfo = classInfo.propertyClassDic[key];
typeStr = childInfo.className;
if (!typeStr) {
typeStr = [key capitalizedString];
}
return [NSString stringWithFormat:@"@property (nonatomic, %@) %@ *%@;",qualifierStr,typeStr,key];
return [NSString stringWithFormat:propertyFormat,qualifierStr,typeStr,key];
}
return [NSString stringWithFormat:@"@property (nonatomic, %@) %@ *%@;",qualifierStr,typeStr,key];
return [NSString stringWithFormat:propertyFormat,qualifierStr,typeStr,key];
}


Expand Down
2 changes: 2 additions & 0 deletions ESJsonFormat/Setting/ESJsonFormatSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
@property BOOL outputToFiles;
@property BOOL uppercaseKeyWordForId;

@property BOOL propertyPosition;

@end
11 changes: 11 additions & 0 deletions ESJsonFormat/Setting/ESJsonFormatSetting.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
NSString *const kESJsonFormatOutputToFiles = @"com.EnjoySR.ESJsonFormat.OutputToFiles";
NSString *const kESJsonFormatImpObjClassInArray = @"com.EnjoySR.ESJsonFormat.ImpObjClassInArray";
NSString *const kESJsonFormatUppercaseKeyWordForId = @"com.EnjoySR.ESJsonFormat.UppercaseKeyWordForId";
NSString *const kESJsonFormatPropertyPosition = @"com.EnjoySR.ESJsonFormat.PropertyPosition";

@implementation ESJsonFormatSetting

Expand All @@ -26,6 +27,7 @@ + (ESJsonFormatSetting *)defaultSetting
kESJsonFormatOutputToFiles: @NO,
kESJsonFormatImpObjClassInArray: @YES,
kESJsonFormatUppercaseKeyWordForId: @NO};
// kESJsonFormatPropertyPosition: @NO,};
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
});
return defaultSetting;
Expand Down Expand Up @@ -67,4 +69,13 @@ - (BOOL)uppercaseKeyWordForId{
return [[NSUserDefaults standardUserDefaults] boolForKey:kESJsonFormatUppercaseKeyWordForId];
}

- (void)setPropertyPosition:(BOOL)propertyPosition{
[[NSUserDefaults standardUserDefaults] setBool:propertyPosition forKey:kESJsonFormatPropertyPosition];
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (BOOL)propertyPosition{
return [[NSUserDefaults standardUserDefaults] boolForKey:kESJsonFormatPropertyPosition];
}

@end