shell脚本-Objective-C自动生成属性声明

#!/bin/bash
#用途:Objective-C自动生成属性声明
#文件名:propGenerate.sh
#参数:属性名数组
#使用方法:./propGenerate.sh "testCount isTest test testArr testMArr testView testLbl testBtn testImgV"

#如果result.txt文件存在就删除它
if [[ -f "result.txt" ]]; then
    rm result.txt
fi

#model属性snippet
intPropTemplate='@property (nonatomic, assign) NSInteger intPropName;'
stringPropTemplate='@property (nonatomic, copy) NSString *stringPropName;'
boolPropTemplate='@property (nonatomic, assign) BOOL boolPropName;'
arrayPropTemplate='@property (nonatomic, strong) NSArray *arrayPropName;'
mutableArrayPropTemplate='@property (nonatomic, strong) NSMutableArray *mutableArrayPropName;'


#UI属性snippet
viewPropTemlpate='@property (nonatomic, strong) UIView *viewPropName;'
labelPropTemplate='@property (nonatomic, strong) UILabel *labelPropName;'
buttonPropTemplate='@property (nonatomic, strong) UIButton *buttonPropName;'
imageViewPropTemplate='@property (nonatomic, strong) UIImageView *imageViewPropName;'

echo "输入的属性名称:"

for var in $1
do 
    echo $var
    #UI属性生成
    if [[ $var == *View ]]; then
        echo $viewPropTemlpate | sed "s/viewPropName/$var/" >> result.txt
    elif [[ $var == *Lbl ]]; then
        echo $labelPropTemplate | sed "s/labelPropName/$var/" >> result.txt
    elif [[ $var == *ImgV ]]; then
        echo $imageViewPropTemplate | sed "s/imageViewPropName/$var/" >> result.txt
    elif [[ $var == *Btn ]]; then
        echo $buttonPropTemplate | sed "s/buttonPropName/$var/" >> result.txt
    #model属性生成
    elif [[ $var == *Time || $var == *Count ]]; then
        echo $intPropTemplate | sed "s/intPropName/$var/" >> result.txt
    elif [[ $var == is* || $var == has* ]]; then
        echo $boolPropTemplate | sed "s/boolPropName/$var/" >> result.txt
    elif [[ $var == *MArr ]]; then
        echo $mutableArrayPropTemplate | sed "s/mutableArrayPropName/$var/" >> result.txt
    elif [[ $var == *Arr ]]; then
        echo $arrayPropTemplate | sed "s/arrayPropName/$var/" >> result.txt
    else
        echo $stringPropTemplate | sed "s/stringPropName/$var/" >> result.txt
    fi
done

echo " "
echo "--------我是分割线----------"
echo " "

#终端直接输出结果
echo "输出的属性声明结果:"
cat result.txt

#输出结果之后移除result.txt文件
rm result.txt

你可能感兴趣的:(shell脚本-Objective-C自动生成属性声明)