2009-07-20 10 views

उत्तर

7

मैं एक्सेसोरिज़र का उपयोग करता हूं जो यह और बहुत कुछ करता है।

http://www.kevincallahan.org/software/accessorizer.html

बहुत सस्ती और शक्तिशाली

+0

सुझाव के लिए धन्यवाद - मैं एक नज़र डालेगा। –

2

यह वह है जिसे मैंने बहुत समय पहले पाया था, जिसे मैंने बहुत समय पहले पाया था, पाइथन में फिर से लिखा गया था और इसके साथ-साथ यह कई चीजों के साथ कई गुणों को उत्पन्न कर सकता है।

यह विशेषता के रूप में (प्रतिलिपि) का उपयोग कर सभी चयनित आवृत्ति चर के लिए गुण उत्पन्न करेगा।

अभी भी कई @interfaces या @implementations के साथ कुछ किनारे के मामले हैं, साथ ही कुछ असामान्य पहचानकर्ता या तारांकन प्लेसमेंट (जैसे * कॉन्स में) हैं, लेकिन इसमें सबसे सामान्य कोडिंग शैलियों को शामिल करना चाहिए। यदि आप इनमें से किसी भी मामले को ठीक करते हैं तो संशोधनों को संपादित/पोस्ट करने के लिए स्वतंत्र महसूस करें।

#!/usr/bin/python 

# Takes a header file with one or more instance variables selected 
# and creates properties and synthesize directives for the selected properties. 

# Accepts google-style instance variables with a tailing underscore and 
# creates an appropriately named property without underscore. 

# Entire Document 
# Home Directory 
# Discard Output 
# Display in Alert 

import os 
import re 
import subprocess 

# AppleScripts for altering contents of files via Xcode 
setFileContentsScript = """\ 
on run argv 
    set fileAlias to POSIX file (item 1 of argv) 
    set newDocText to (item 2 of argv) 
    tell application "Xcode" 
     set doc to open fileAlias 
     set text of doc to newDocText 
    end tell 
end run \ 
""" 

getFileContentsScript = """\ 
on run argv 
    set fileAlias to POSIX file (item 1 of argv) 
    tell application "Xcode" 
     set doc to open fileAlias 
     set docText to text of doc 
    end tell 
    return docText 
end run \ 
""" 

# Get variables from Xcode 
headerFileText = """%%%{PBXAllText}%%%""" 
selectionStartIndex = %%%{PBXSelectionStart}%%% 
selectionEndIndex = %%%{PBXSelectionEnd}%%% 
selectedText = headerFileText[selectionStartIndex:selectionEndIndex] 

headerFilePath = """%%%{PBXFilePath}%%%""" 

# Look for an implementation file with .m or .mm extension 
implementationFilePath = headerFilePath[:-1] + "m" 
if not os.path.exists(implementationFilePath): 
    implementationFilePath += "m" 

instanceVariablesRegex = re.compile(
    """^\s*((?:(?:\w+)\s+)*(?:(?:\w+)))""" + # Identifier(s) 
    """([*]?)\\s*""" + # An optional asterisk 
    """(\\w+?)(_?);""", # The variable name 
    re.M) 

# Now for each instance variable in the selected section 
properties = "" 
synthesizes = "" 

for lineMatch in instanceVariablesRegex.findall(selectedText): 
    types = " ".join(lineMatch[0].split()) # Clean up consequtive whitespace 
    asterisk = lineMatch[1] 
    variableName = lineMatch[2] 
    trailingUnderscore = lineMatch[3] 

    pointerPropertyAttributes = "(copy) " # Attributes if variable is pointer 
    if not asterisk: 
     pointerPropertyAttributes = "" 

    newProperty = "@property %s%s %s%s;\n" % (pointerPropertyAttributes, 
              types, 
              asterisk, 
              variableName) 

    # If there's a trailing underscore, we need to let the synthesize 
    # know which backing variable it's using 
    newSynthesize = "@synthesize %s%s;\n" % (variableName, 
              trailingUnderscore and 
              " = %s_" % variableName) 

    properties += newProperty 
    synthesizes += newSynthesize 

# Check to make sure at least 1 properties was found to generate 
if not properties: 
    os.sys.stderr.writelines("No properties found to generate") 
    exit(-1) 

# We want to insert the new properties either immediately after the last 
# existing property or at the end of the instance variable section 
findLastPropertyRegex = re.compile("^@interface.*?{.*?}.*?\\n" + 
            "(?:.*^\\s*@property.*?\\n)?", re.M | re.S) 
headerInsertIndex = findLastPropertyRegex.search(headerFileText).end() 

# Add new lines on either side if this is the only property in the file 
addedNewLine = "\n" 
if re.search("^\s*@property", headerFileText, re.M): 
    # Not the only property, don't add 
    addedNewLine = "" 

newHeaderFileText = "%s%s%s%s" % (headerFileText[:headerInsertIndex], 
           addedNewLine, 
           properties, 
           headerFileText[headerInsertIndex:]) 

subprocess.call(["osascript", 
       "-e", 
       setFileContentsScript, 
       headerFilePath, 
       newHeaderFileText]) 


if not os.path.exists(implementationFilePath): 
    os.sys.stdout.writelines("No implementation file found") 
    exit(0) 

implementationFileText = subprocess.Popen(
    ["osascript", 
    "-e", 
    getFileContentsScript, 
    implementationFilePath], 
    stdout=subprocess.PIPE).communicate()[0] 

# We want to insert the synthesizes either immediately after the last existing 
# @synthesize or after the @implementation directive 
lastSynthesizeRegex = re.compile("^\\s*@implementation.*?\\n" + 
           "(?:.*^\\s*@synthesize.*?\\n)?", re.M | re.S) 

implementationInsertIndex = \ 
    lastSynthesizeRegex.search(implementationFileText).end() 

# Add new lines on either side if this is the only synthesize in the file 
addedNewLine = "\n" 
if re.search("^\s*@synthesize", implementationFileText, re.M): 
    # Not the only synthesize, don't add 
    addedNewLine = "" 

newImplementationFileText = "%s%s%s%s" % \ 
        (implementationFileText[:implementationInsertIndex], 
        addedNewLine, 
        synthesizes, 
        implementationFileText[implementationInsertIndex:]) 

subprocess.call(["osascript", 
       "-e", 
       setFileContentsScript, 
       implementationFilePath, 
       newImplementationFileText]) 

# Switch Xcode back to header file 
subprocess.Popen(["osascript", 
        "-e", 
        getFileContentsScript, 
        headerFilePath], 
       stdout=subprocess.PIPE).communicate() 
+0

उह चीजों को आसान को पढ़ने के लिए, और तेजी से बनाता है, ऐसा नहीं है दो ई के साथ "संश्लेषण"? मुझे लगता है कि यह स्क्रिप्ट संभवतः "synthsize" वर्तनी के साथ ठीक तरह से काम नहीं कर सकती है। – n8gray

+0

हां, इसे इंगित करने के लिए धन्यवाद। –

0

कुछ घंटे बाद मैंने इस प्रश्न में आने से पहले @property निर्देशों को करने के लिए कल लिखा था। यह एक साधारण पाठ फ़िल्टर है और इसे @ सिंथेसाइज निर्देशों तक विस्तारित करने के लिए तुच्छ होगा (case कथन के लिए उचित 0 जोड़ें और when block_end स्थिति में उपयुक्त जोड़ दें), और कई घटनाओं को संभालने के लिए इसे बढ़ाने के लिए और अधिक काम नहीं करना @ एक फ़ाइल में इंटरफेस/@ कार्यान्वयन (उनके नाम पर नज़र रखने से --- यह, regexp कैप्चर के माध्यम से किया जा सकता है के रूप में सब कुछ स्क्रिप्ट में है):

#! /usr/bin/ruby 

# -------------- Basic Definitions ----------------------------- 

doc = "%%%{PBXFilePath}%%%" 

# regular expressions 

search_exp = /[[:space:]]*([[a-zA-Z0-9]]*)[[:space:]]\*([a-zA-Z0-9]*)/ 
interface_start = /@interface/ 
block_end = /^\}/ 

#initializing variables 

properties_list = [] 
properties_string = "" 
reading_interface = 0 

#---------------- Start Processing ----------------------------- 

file = File.open(doc, "r").readlines 

file.each do |line| 

# capture the regular expression matches only in the 
# interface declaration and print out the matching 
# property declarations 

    case line 

    # start capturing 
    when interface_start 
    reading_interface = 1 
    puts line 

    # capture and keep in properties_list 
    when search_exp 
    if (reading_interface == 1) then 
     data = Regexp.last_match 
     properties_list << data 
    end 
    puts line 

    # unpack properties_list and print out the property 
    # declarations 
    when block_end 
    if (reading_interface == 1) then 
     reading_interface = 0 
     properties_list.each do |pair| 
     properties_string << "@property (readwrite, copy) #{pair[0].lstrip};\n" 
     end 
     puts line 
     puts "\n" + properties_string 
    end 
    else puts line 
    end 

end 

मैं इस "कोई इनपुट" और का उपयोग कर चलाने "की जगह दस्तावेज़ सामग्री "उपयोगकर्ता स्क्रिप्ट संपादक में I/O के विकल्पों के रूप में।

1

यहां वर्तमान में उपयोग की जाने वाली उपयोगकर्तास्क्रिप्ट है - यह एक समय में एक आवृत्ति चर पर काम करता है। यह सही रखरखाव तंत्र (सरल प्रकारों को बनाए रखा नहीं जाता है) का उपयोग करने का प्रयास करता है, और यह कार्यान्वयन फ़ाइल में @ सिंथेसाइज स्टेटमेंट भी बनाता है - वर्तमान में यह अभी तक आपके लिए डेलोक स्टेटमेंट नहीं बना रहा है।

#! /usr/bin/perl -w 

#Input: Selection 
#Directory: Selection 
#Output: Display in Alert 
#Errors: Display in Alert 

use strict; 

# Get the header file contents from Xcode user scripts 
my $headerFileContents = <<'HEADERFILECONTENTS'; 
%%%{PBXAllText}%%% 
HEADERFILECONTENTS 

# Get the indices of the selection from Xcode user scripts 
my $selectionStartIndex = %%%{PBXSelectionStart}%%%; 
my $selectionEndIndex = %%%{PBXSelectionEnd}%%%; 

# Get path of the header file 
my $implementationFilePath = "%%%{PBXFilePath}%%%"; 
my $headerFilePath = $implementationFilePath; 

# Look for an implemenation file with a ".m" or ".mm" extension 
$implementationFilePath =~ s/\.[hm]*$/.m/; 
if (!(-e $implementationFilePath)) 
{ 
    $implementationFilePath =~ s/.m$/.mm/; 
} 

# Handle subroutine to trime whitespace off both ends of a string 
sub trim 
{ 
    my $string = shift; 
    $string =~ s/^\s*(.*?)\s*$/$1/; 
    return $string; 
} 


# Get the selection out of the header file 
my $selectedText = substr $headerFileContents, $selectionStartIndex, ($selectionEndIndex - $selectionStartIndex); 

#my $otherText = substr $headerFileContents, $selectionStartIndex; 
#my $pulledText = ""; 
#if (length($otherText) && $otherText =~ /.*$(^.*;).*/) 
#{ 
# $pulledText = $1; 
#} 
# 
# 
#print $pulledText; 


$selectedText = trim $selectedText; 


my $type = ""; 
my $asterisk = ""; 
my $name = ""; 
my $behavior = ""; 
my $iboutlet = ""; 

# Test that the selection is: 
# At series of identifiers (the type name and access specifiers) 
# Possibly an asterisk 
# Another identifier (the variable name) 
# A semi-colon 
if (length($selectedText) && ($selectedText =~ /([_A-Za-z][_A-Za-z0-9]*\s*)+([\s\*]+)([_A-Za-z][_A-Za-z0-9]*)/)) 
{ 
    $type = $1; 
    $type = trim $type; 
    $asterisk = $2; 
    $asterisk = trim $asterisk; 
    $name = $3; 
    $behavior = ""; 
    if (defined($asterisk) && length($asterisk) == 1) 
    { 
     $behavior = "(nonatomic, retain) "; 
    } 
    else 
    { 
     $behavior = "(nonatomic) "; 
     $asterisk = ""; 
    } 
} 
else 
{ 
    print "Bailing, error in Regex"; 
    exit 1; 
} 

# special case, see if we need to keep around an IBOUTLET declaration. 
if (length($selectedText) && ($selectedText =~ /IBOutlet/)) 
{ 
    $iboutlet = "IBOutlet "; 
} 

# Find the closing brace (end of the class variables section) 
my $remainderOfHeader = substr $headerFileContents, $selectionEndIndex; 
my $indexAfterClosingBrace = $selectionEndIndex + index($remainderOfHeader, "\n}\n") + 3; 
if ($indexAfterClosingBrace == -1) 
{ 
    exit 1; 
} 

# Determine if we need to add a newline in front of the property declaration 
my $leadingNewline = "\n"; 
if (substr($headerFileContents, $indexAfterClosingBrace, 1) eq "\n") 
{ 
    $indexAfterClosingBrace += 1; 
    $leadingNewline = ""; 
} 

# Determine if we need to add a newline after the property declaration 
my $trailingNewline = "\n"; 
if (substr($headerFileContents, $indexAfterClosingBrace, 9) eq "\@property") 
{ 
    $trailingNewline = ""; 
} 

# Create and insert the proper declaration 
my $propertyDeclaration = $leadingNewline . "\@property " . $behavior . $iboutlet . $type . " " . $asterisk . $name . ";\n" . $trailingNewline; 
substr($headerFileContents, $indexAfterClosingBrace, 0) = $propertyDeclaration; 

my $replaceFileContentsScript = <<'REPLACEFILESCRIPT'; 
on run argv 
    set fileAlias to POSIX file (item 1 of argv) 
    set newDocText to (item 2 of argv) 
    tell application "Xcode" 
     set doc to open fileAlias 
     set text of doc to newDocText 
    end tell 
end run 
REPLACEFILESCRIPT 

# Use Applescript to replace the contents of the header file 
# (I could have used the "Output" of the Xcode user script instead) 
system 'osascript', '-e', $replaceFileContentsScript, $headerFilePath, $headerFileContents; 

# Stop now if the implementation file can't be found 
if (!(-e $implementationFilePath)) 
{ 
    exit 1; 
} 

my $getFileContentsScript = <<'GETFILESCRIPT'; 
on run argv 
    set fileAlias to POSIX file (item 1 of argv) 
    tell application "Xcode" 
     set doc to open fileAlias 
     set docText to text of doc 
    end tell 
    return docText 
end run 
GETFILESCRIPT 

# Get the contents of the implmentation file 
open(SCRIPTFILE, '-|') || exec 'osascript', '-e', $getFileContentsScript, $implementationFilePath; 
my $implementationFileContents = do {local $/; <SCRIPTFILE>}; 
close(SCRIPTFILE); 

# Look for the class implementation statement 
if (length($implementationFileContents) && ($implementationFileContents =~ /(\@implementation [_A-Za-z][_A-Za-z0-9]*\n)/)) 
{ 
    my $matchString = $1; 
    my $indexAfterMatch = index($implementationFileContents, $matchString) + length($matchString); 

    # Determine if we want a newline before the synthesize statement 
    $leadingNewline = "\n"; 
    if (substr($implementationFileContents, $indexAfterMatch, 1) eq "\n") 
    { 
     $indexAfterMatch += 1; 
     $leadingNewline = ""; 
    } 

    # Determine if we want a newline after the synthesize statement 
    $trailingNewline = "\n"; 
    if (substr($implementationFileContents, $indexAfterMatch, 11) eq "\@synthesize") 
    { 
     $trailingNewline = ""; 
    } 

    # Create and insert the synthesize statement 
    my $synthesizeStatement = $leadingNewline . "\@synthesize " . $name . ";\n" . $trailingNewline; 
    substr($implementationFileContents, $indexAfterMatch, 0) = $synthesizeStatement; 

    # Use Applescript to replace the contents of the implementation file in Xcode 
    system 'osascript', '-e', $replaceFileContentsScript, $implementationFilePath, $implementationFileContents; 
} 

exit 0; 
0

एक्सेसोरिज़र http://www.kevincallahan.org/software/accessorizer.html यह सामान और बहुत कुछ करता है। यह कस्टम उपसर्ग और पोस्टफिक्सेस (प्रत्यय) को भी संभालता है। अगर आप Google के अंडरस्कोर चाहते हैं, तो आपको मिल गया। यदि आप इसे बदलना चाहते हैं, तो इसे फ्लाई पर बदलें - स्क्रिप्ट संपादित करने की आवश्यकता नहीं है। इसके अलावा, एक डिफ़ॉल्ट तालिका है जहां आप पास किए गए ivar के प्रकार (प्रतिलिपि, बनाए रखने, पढ़ने, असाइन आदि) के आधार पर डिफ़ॉल्ट संपत्ति विनिर्देशों को परिभाषित कर सकते हैं। यह आईबीओलेट का पता लगाता है और स्वचालित रूप से आईबीओलेट कीवर्ड को सम्मिलित करता है, -viewDidUnload के लिए आपके विचारों को निगलता है, डेलोक की कई शैलियों करता है। यह संग्रह के लिए उन सभी बालों वाले एक्सेसर्स भी लिखता है (एनएसएमयूटेबलएरे और एनएसएसएटी)। यह कुंजी संग्रह, विभिन्न लॉकिंग दृष्टिकोण करता है, यह आपकी संपत्ति को सॉर्ट कर सकता है और ब्लॉक को संश्लेषित कर सकता है, केवीओ कोड, सिंगलटन कोड, चयनकर्ता में कनवर्ट, हेडरडॉक टैग, एनएसएलओजी() और अधिक उत्पन्न कर सकता है ... इसके लिए एक लचीली शैली टैब भी है कस्टम तर्क नाम आदि के लिए, नई लाइन पर ब्रेसिज़ डालने या नहीं, स्पेस के लिए, अधिकांश चीजें सेवाओं के माध्यम से संभाली जाती हैं, इसलिए आप बस अपने इवर ब्लॉक का चयन करें, एक कीस्ट्रोक या दो दबाएं और आप कर चुके हैं। यदि आप डॉक में एक्सेसोरिज़र को कम करते हैं, तो इसका इंटरफ़ेस फ्रंट पर नहीं आता है, जिससे आप एक्सकोड या सेवाओं का समर्थन करने वाले किसी भी अन्य संपादक में ध्यान केंद्रित कर सकते हैं। बेशक, एक्सेसोरिज़र स्पष्ट एक्सेसर्स (जैसे उद्देश्य-सी 1.0 में भी) लिखता है और आपको गुणों को ओवरराइड करने की अनुमति देता है - सभी स्विच के एक साधारण टॉगल के साथ। आप पास किए गए प्रकार के आधार पर ओवरराइड को भी कस्टमाइज़ कर सकते हैं। इसे देखने के लिए वीडियो देखें।

2

यह Xcode 3.2.4 कि उत्पन्न करता है के लिए एक अजगर स्क्रिप्ट है, इंटरफेस गुण, कार्यान्वयन संश्लेषण, और dealloc है। इंस्टॉल करने के लिए, इस स्क्रिप्ट को कॉपी करें, एक्सकोड स्क्रिप्ट मेनू (2 से आखिरी) पर जाएं "उपयोगकर्ता स्क्रिप्ट संपादित करें ..." इसे कोड के तहत जोड़ें, एक नया स्क्रिप्ट नाम बनाएं, और नीचे पाइथन लिपि पेस्ट करें।

उपयोग करने के लिए बस @interface के अंतर्गत चर का चयन करें, फिर इस स्क्रिप्ट को कॉल करें। इसके बाद कार्यान्वयन और सभी @ सिंथेसिस और डेलोक के कार्यान्वयन में सभी @ संपत्तियों को जोड़ दिया जाएगा। यह आपके किसी भी लेबल या बटन में आईबीओलेट नहीं जोड़ पाएगा क्योंकि यह इसे नहीं जानता है, लेकिन यह मैन्युअल रूप से जोड़ना आसान है।

नीचे लिपि का इंडेंटेशन महत्वपूर्ण है इसलिए इसे न बदलें।

#!/usr/bin/python 


# Takes a header file with one or more instance variables selected 
# and creates properties and synthesize directives for the selected properties. 

# Accepts google-style instance variables with a tailing underscore and 
# creates an appropriately named property without underscore. 

# Xcode script options should be as follows: 
# Entire Document 
# Home Directory 
# Discard Output 
# Display in Alert 

import os 
import re 
import subprocess 

# AppleScripts for altering contents of files via Xcode 
setFileContentsScript = """\ 
on run argv 
set fileAlias to POSIX file (item 1 of argv) 
set newDocText to (item 2 of argv) 
tell application "Xcode" 
set doc to open fileAlias 
set text of doc to newDocText 
end tell 
end run \ 
""" 

getFileContentsScript = """\ 
on run argv 
set fileAlias to POSIX file (item 1 of argv) 
tell application "Xcode" 
set doc to open fileAlias 
set docText to text of doc 
end tell 
return docText 
end run \ 
""" 

# Get variables from Xcode 
headerFileText = """%%%{PBXAllText}%%%""" 
selectionStartIndex = %%%{PBXSelectionStart}%%% 
selectionEndIndex = %%%{PBXSelectionEnd}%%% 
selectedText = headerFileText[selectionStartIndex:selectionEndIndex] 

headerFilePath = """%%%{PBXFilePath}%%%""" 

# Look for an implementation file with .m or .mm extension 
implementationFilePath = headerFilePath[:-1] + "m" 
if not os.path.exists(implementationFilePath): 
implementationFilePath += "m" 

instanceVariablesRegex = re.compile(
"""^\s*((?:(?:\\b\w+\\b)\s+)*(?:(?:\\b\\w+\\b)))\\s*""" + # Identifier(s) 
"""([*]?)\\s*""" + # An optional asterisk 
"""(\\b\\w+?)(_?\\b);""", # The variable name 
re.M) 

# Now for each instance variable in the selected section 
properties = "" 
synthesizes = "" 
deallocs = "" 

for lineMatch in instanceVariablesRegex.findall(selectedText): 
    types = " ".join(lineMatch[0].split()) # Clean up consequtive whitespace 

    asterisk = lineMatch[1] 
    variableName = lineMatch[2] 
    trailingUnderscore = lineMatch[3] 

    pointerPropertyAttributes = "(nonatomic, retain) " # Attributes if variable is pointer 
    if not asterisk: 
     pointerPropertyAttributes = "(nonatomic, assign) " 

    newProperty = "@property %s%s %s%s;\n" % (pointerPropertyAttributes, 
             types, 
             asterisk, 
             variableName) 

    # If there's a trailing underscore, we need to let the synthesize 
    # know which backing variable it's using 
    newSynthesize = "@synthesize %s%s;\n" % (variableName, 
            trailingUnderscore and 
            " = %s_" % variableName) 
    # only do the objects 
    if asterisk: 
     newDealloc = " [%s%s release];\n" % (variableName, 
        trailingUnderscore and 
           " = %s_" % variableName) 
    properties += newProperty 
    synthesizes += newSynthesize 
    # only add if it's an object 
    if asterisk: 
     deallocs += newDealloc 


# Check to make sure at least 1 properties was found to generate 
if not properties: 
    os.sys.stderr.writelines("No properties found to generate") 
    exit(-1) 

# We want to insert the new properties either immediately after the last 
# existing property or at the end of the instance variable section 
findLastPropertyRegex = re.compile("^@interface.*?{.*?}.*?\\n" + 
         "(?:.*^\\s*@property.*?\\n)?", re.M | re.S) 
headerInsertIndex = findLastPropertyRegex.search(headerFileText).end() 

# Add new lines on either side if this is the only property in the file 
addedNewLine = "\n" 
if re.search("^\s*@property", headerFileText, re.M): 
    # Not the only property, don't add 
    addedNewLine = "" 

newHeaderFileText = "%s%s%s%s" % (headerFileText[:headerInsertIndex], 
         addedNewLine, 
         properties, 
         headerFileText[headerInsertIndex:]) 

subprocess.call(["osascript", 
     "-e", 
     setFileContentsScript, 
     headerFilePath, 
     newHeaderFileText]) 


if not os.path.exists(implementationFilePath): 
    os.sys.stdout.writelines("No implementation file found") 
    exit(0) 

implementationFileText = subprocess.Popen(
["osascript", 
"-e", 
getFileContentsScript, 
implementationFilePath], 
stdout=subprocess.PIPE).communicate()[0] 

# We want to insert the synthesizes either immediately after the last existing 
# @synthesize or after the @implementation directive 
lastSynthesizeRegex = re.compile("^\\s*@implementation.*?\\n" + 
         "(?:.*^\\s*@synthesize.*?\\n)?", re.M | re.S) 

implementationInsertIndex = \ 
lastSynthesizeRegex.search(implementationFileText).end() 

# Add new lines on either side if this is the only synthsize in the file 
addedNewLine = "\n" 
if re.search("^\s*@synthesize", implementationFileText, re.M): 
    # Not the only synthesize, don't add 
    addedNewLine = "" 

newImplementationFileText = "%s%s%s%s" % \ 
     (implementationFileText[:implementationInsertIndex], 
     addedNewLine, 
     synthesizes, 
     implementationFileText[implementationInsertIndex:]) 

subprocess.call(["osascript", 
     "-e", 
     setFileContentsScript, 
     implementationFilePath, 
     newImplementationFileText]) 


implementationFileText = subprocess.Popen(
["osascript", 
"-e", 
getFileContentsScript, 
implementationFilePath], 
stdout=subprocess.PIPE).communicate()[0] 

# We want to insert the deallocs either immediately after the last existing 
# [* release] or after the [super dealloc] 
lastDeallocRegex = re.compile("^\\s+\[super dealloc\];?\\n" + 
         "(?:.*^\\s+\[\w release\];?\\n)?", re.M | re.S) 

deallocInsertIndex = \ 
lastDeallocRegex.search(implementationFileText).end() 

addedNewDeallocLine = "\n" 
if re.search("^\s*\[\w release\];?", implementationFileText, re.M): 
# Not the only dealloc, don't add 
addedNewDeallocLine = "" 


newImplementationFileText = "%s%s%s%s" % \ 
     (implementationFileText[:deallocInsertIndex], 
      addedNewDeallocLine, 
      deallocs, 
      implementationFileText[deallocInsertIndex:]) 

subprocess.call(["osascript", 
       "-e", 
       setFileContentsScript, 
       implementationFilePath, 
       newImplementationFileText])  

# Switch Xcode back to header file 
subprocess.Popen(["osascript", 
     "-e", 
     getFileContentsScript, 
     headerFilePath], 
     stdout=subprocess.PIPE).communicate() 
1

वाह, यहां पर बहुत सारी पागल स्क्रिप्टिंग चल रही है।

Xcode 4.4 (शायद पहले) ...

@property (assign) BOOL automatically; 
@property (strong) NSArray *believeDat; 

के माध्यम से

self.automatically = YES; 

और "accessored" किया जा सकता है आपका IVAR रों ऑटो संश्लेषित हो जाएगा .. उदाहरण के लिए .. के रूप में उदाहरण के वैरिएबल को ऑटो-जेनरेट-टू-लीड-अंडरस्कोर के माध्यम से सीधे संपादित करें ..

_believeDat = @["thank you, jesus", @"mary poopins"]; 

नहीं @synthesize आवश्यक है।

ऐसे @property की त्वरित और आसान प्रविष्टि के लिए ... एक बार में "कोड स्निपेट" लाइब्रेरी में निम्न को खींचें .. और आप इन कूद-बंद बिंदुओं को दर्ज करने के लिए कीबोर्ड शॉर्टकट असाइन कर सकते हैं गुण अधिक तेज़ी से। मैं वस्तुओं के लिए RRR और पुरातन के लिए aaa का उपयोग .. लेकिन सिर्फ मुझे thats ..

@property (nonatomic, assign) <#type#> <#name#>;

@property (nonatomic, retain) <#type#> *<#name#>;

पिछले नहीं बल्कि कम से कम, और कुछ मुझे पागल कॉल कर सकते हैं .. लेकिन मैंने निम्नलिखित मैक्रोज़ को .pch में आगे बढ़ाने, स्पष्ट करने और प्रक्रिया में स्वागत की कमी लाने के लिए फेंक दिया .. सभी सामान्य मैक्रो अस्वीकरण लागू होते हैं ...

#define RONLY readonly 
#define RDWRT readwrite 
#define NATOM nonatomic 
#define STRNG strong 
#define ASS assign 
#define CP copy 
#define SET setter 
#define GET getter 
एप्पल कक्षाओं के लिए इसी तरह संरचित #define रों ( #define NSA NSArray \ #define NSS NSString) के साथ

, इस (मेरे लिए) दर्ज करने के लिए, की तरह लग रही ...

@property (NATOM, STRNG) NSA* fonts; 
@property (NATOM, STRNG) NSS* cachedPath; 
+0

तो क्या आपका मतलब है कि सभी @property स्वचालित रूप से संश्लेषित कर चुके हैं? संश्लेषण को परिभाषित करने की कोई ज़रूरत नहीं है? – Dejell

संबंधित मुद्दे