Convert file references in Xcode to files - xcode

I am new to XCode and I want to convert file references from another project into files in my project folder. I should've done the copying to folder at the time I did a drag and drop but unfortunately I didn't notice at that time.
I tried removing the references and manually copying the said files into my project folder but that is causing build errors I can't understand. Xcode is unable to recognize the classes in the newly copied files.
When I remove the references to the files I see the following diff being generated in the project.pbxproj file
- 9EA3AE481AFBE3DC006D1736 /* PasscodeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE3F1AFBE3DC006D1736 /* PasscodeLock.swift */; };
- 9EA3AE491AFBE3DC006D1736 /* PasscodeLockPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE401AFBE3DC006D1736 /* PasscodeLockPresenter.swift */; };
- 9EA3AE4A1AFBE3DC006D1736 /* ChangePasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE421AFBE3DC006D1736 /* ChangePasscodeState.swift */; };
- 9EA3AE4B1AFBE3DC006D1736 /* ConfirmPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE431AFBE3DC006D1736 /* ConfirmPasscodeState.swift */; };
- 9EA3AE4C1AFBE3DC006D1736 /* EnterPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE441AFBE3DC006D1736 /* EnterPasscodeState.swift */; };
- 9EA3AE4D1AFBE3DC006D1736 /* PasscodesMismatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE451AFBE3DC006D1736 /* PasscodesMismatchState.swift */; };
- 9EA3AE4E1AFBE3DC006D1736 /* SetPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE461AFBE3DC006D1736 /* SetPasscodeState.swift */; };
Is there an easy way to convert all these references into files in my project folder?

I was able to individually copy the files and build. The mistake I was making was that I was adding a files to an extra target.

Related

What is xcLanguageSpecificationIdentifier for?

After you make global search and replace operation in Xcode it adds xcLanguageSpecificationIdentifier and lineEnding to every manipulated file entry in *.pbxproj files in the form of e.g.:
036B04CB1B2AE8A70010F649 /* MyClass.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyClass.m; sourceTree = "<group>"; };
to:
036B04CB1B2AE8A70010F649 /* MyClass.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = MyClass.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
What is it for?
Does it improve something like search performance?
If yes, how can I generate it for other files without making search and replace operation?
If no, how can I prevent Xcode from creating such things?
I think xcLanguageSpecificationIdentifier is just a temporary indication from Xcode 6 with Swift's comming; and you can find it in your project.pbxproj if you write mixture code with Swift and objc.
For example, you have ProfileVC.h and ProfileVC.m, then you delete ProfileVC.h and rename ProfileVC.m to ProfileVC.swift (and rewrite it in Swift), in your projectName.xcodeproject/project.pbxproj, some line change from
49E89AB31C3D4494006C95BB /* ProfileVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProfileVC.m; sourceTree = "<group>";};
to
49E89AB31C3D4494006C95BB /* ProfileVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ProfileVC.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
However, in this situation, code in ProfileVC.swift seems not correctly colored, and code completion is broken. I delete the part xcLanguageSpecificationIdentifier = xcode.lang.objc; and everything goes quite OK.

dsPIC33EV256GM002 PWM settings

I developed a simple program to produce PWM waveform on dsPIC33EV256GM002 but I can't disable it. I used PWM1 and PWM2 and I would generate PWM waveform on PWM1L1 pin (pin 26 on DIP package) maintain PWM1H1 (pin 25 on DIP package) as digital I/O.
Teorically the PWM register setting:
IOCON1bits.PENL = 1; /* PWM1L is controlled by PWM module /
IOCON1bits.PENH = 0; / PWM1H is controlled by GPIO module */
should do that but, using and oscilloscope, I noticed the PWM waveform on PWM1H1 pin, with opposite value (when PWM1L is 1 PWM1H is 0 and veceversa) even if it should be a digital I/O.
Did you find any similar problem ?
Thank you very much for your help and cooperation
regards
I used the following code:
TRISBbits.TRISB10 = 0; /* Set as a digital output */
TRISBbits.TRISB11 = 0; /* Set as a digital output */
TRISBbits.TRISB12 = 0; /* Set as a digital output */
TRISBbits.TRISB13 = 0; /* Set as a digital output */
TRISBbits.TRISB14 = 0; /* Set as a digital output */
TRISBbits.TRISB15 = 0; /* Set as a digital output */
LATBbits.LATB10 = 0; /* Set as a digital output */
LATBbits.LATB11 = 0; /* Set as a digital output */
LATBbits.LATB12 = 0; /* Set as a digital output */
LATBbits.LATB13 = 0; /* Set as a digital output */
LATBbits.LATB14 = 0; /* Set as a digital output */
LATBbits.LATB15 = 0; /* Set as a digital output */
PORTBbits.RB10=0;
PORTBbits.RB11=0;
PORTBbits.RB12=0;
PORTBbits.RB13=0;
PORTBbits.RB14=0;
PORTBbits.RB15=0;
PTPER = 4000;
/*~~~~~~~~~~ PWM1 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
IOCON1bits.PENL = 1; /* PWM1L is controlled by PWM module */
IOCON1bits.PENH = 0; /* PWM1H is controlled by GPIO module */
IOCON1bits.PMOD = 0; /* Select Independent Output PWM mode */
PDC1 = 500; /* Initial Duty cycle */
DTR1 = 0; /* Deadtime setting */
ALTDTR1 = 0; /* Deadtime setting */
PHASE1 = 0; /* No phase shift */
/*~~~~~~~~~~~ PWM2 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
IOCON2bits.PENH = 1; /* PWM2H is controlled by PWM module */
IOCON2bits.PENL = 0; /* PWM2L is controlled by GPIO module */
IOCON2bits.PMOD = 0; /* Select Independent Output PWM mode */
PDC2 = 2000; /* Initial Duty cycle */
DTR2 = 0; /* Deadtime setting */
ALTDTR2 = 0; /* Deadtime setting */
PHASE2 = 0; /* */
PTCONbits.PTEN = 1; /* Enable the PWM Module */
The problem was related to the write protection of IOCONxbits register.
I added the following line:
_FDEVOPT( PWMLOCK_OFF );
and this fixed the problem.
I faced same problem with dspic33ev32GP002 and changed configuration bits like so:
// FDEVOPT
#pragma config PWMLOCK = OFF
This worked for me.

calling gccxml from my code (Windows)

I'm writing a tool that makes use of gccxml. Basically I'm parsing the output xml file that has been created by gccxml. This works great on my windows machine in visual studio except for a couple of drawbacks. Here's the current state of my project:
cmake_gui gave me a visual studio solution that compiles perfectly (x64 Release). It's set up to create three executables in E:\cmake_builds\GCCXML\bin\Release.
My own C++ tool is located in a different VS solution file. When it's supposed to make use of gccxml the following code is used:
bool Parser::ParseFile( const std::string& _szFileName, std::string& _gccxmlPath,
const std::string& _tempFileLocation,
std::string& _errorStr)
{
bool retVal = true;
printf("Parsing file %s...\n\n", _szFileName.c_str());
/* format _gccxmlPath, adding a final forward slash to the path if required */
char lastChar = _gccxmlPath.at(_gccxmlPath.length()-1);
if(lastChar != '/' && lastChar != '\\')
_gccxmlPath += "/";
/* set up a temporary environment path variable so that the gccxml exe files may locate each other */
char envPath[500];
sprintf_s(envPath, "PATH=%s", _gccxmlPath.c_str());
const char* gccxml_env[] =
{
/* set path to gccxml directory where all exe files from gccxml are located */
envPath,
0
};
/* path & filename of gccxml.exe */
char gccxml_exe[500];
sprintf_s(gccxml_exe, "%sgccxml.exe", _gccxmlPath.c_str());
/* parameter string used to set gccxml output filename */
char fxmlParam[500];
sprintf_s(fxmlParam, "-fxml=\"%s\"", _tempFileLocation.c_str());
/* synthesize argument list for gccxml*/
/* see: http://gccxml.github.io/HTML/Running.html */
/* and: https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Invoking-GCC.html */
const char* gccxml_args[GCCXML_PARAM_LEN];
unsigned int curPos = 0;
/* 1st argument: exe name */
gccxml_args[curPos++] = "gccxml.exe";
/* the source code to be compiled */
gccxml_args[curPos++] = _szFileName.c_str();
/* try to find out which msvc compiler to use */
gccxml_args[curPos++] = "--gccxml-compiler cl";
/* the output xml file */
gccxml_args[curPos++] = fxmlParam;
/* last argument: zero termination */
gccxml_args[curPos++] = 0;
/* call gccxml & compile the source code file */
if(0 != _spawnvpe(P_WAIT, gccxml_exe, gccxml_args, gccxml_env))
{
_errorStr += "GCCXML Compiler Error";
return false;
}
/* now parse the gccxml output file from tempfile ... */
...
...
return retVal;
}
as you can see I have to set up a local environment PATH variable to make sure the three executables are able to find each other.
This works great for what I want to do.
Unfortunately I can't use this method to call gccxml.exe when I move the three executables to a different directory. Of course I provide the new _gccxmlPath string but gccxml returns
"Support item Vc10/Include is not available..."
telling me that it looked in the folder into which I moved the executables. All my local copies of Vc10/Include however are located somewhere totally different and I don't understand how it had been able find one of these before I moved the executables.
It seems like this problem can be fixed by calling gccxml_vcconfig.exe using the parameters "patch_dir" and providing the directory "gccxml/Source/GCC_XML/VcInstall" from my gccxml source files. I'm, however, not able to solve my issue this way using any of the spawn* commands.
If I do the gccxml_vcconfig.exe runs just fine but after that I'm trying to call gccxml.exe and it turns out that it still looks in the same directory as before.
So gccxml_vcconfig.exe was probably not what I was looking for?
I'm trying to find a way to provide my tool to users who don't want to recompile gccxml on their machine so I'd like to distribute the thre binaries (and what else is needed).
just to let you know. I found a way of doing what I wanted to do. The trick is as follows:
right before vpe-spawning gccxml using its own location as environment (as shown above) vp-spawn the gccxml_vcconfig.exe without providing any environment path variables. This may look like this
std::string VcInstallDir = resolveRelativePath(_gccxmlPath + "../share/gccxml-0.9/VcInstall");
std::string GCCXML09Dir = resolveRelativePath(_gccxmlPath + "../share/gccxml-0.9");
std::vector<const char*> gccxml_config_args;
gccxml_config_args.push_back("gccxml_vcconfig.exe");
gccxml_config_args.push_back(VcInstallDir.c_str());
gccxml_config_args.push_back(GCCXML09Dir.c_str());
gccxml_config_args.push_back(0);
if(0 != _spawnvp(_P_WAIT, gccxml_vcconfig_exe.c_str(), gccxml_config_args.data()))
{
_errorStr += "GCCXML Configuration Error";
return false;
}
note that resolveRelativePath is a self written function for string manipulation that produces a valid absolute path; gccxml_vcconfig_exe contains the absolute path to my exe file
and I somewhat changed my coding style from arrays to std::vectors as you can see

Is there anyway to make SOMETHING automatically add selected file extension to filename, when OPENFILENAME struct and GetSaveFileName() are used?

I have this function:
void PickupFileAndSave(std::vector<unsigned char> file_data, int *error_code, char *file_mask = "All files (*.*)\0*.*\0\0")
{
OPENFILENAMEA ofn; // common dialog box structure
char szFile[MAX_PATH]; // buffer for file name
char initial_dir[MAX_PATH] = { 0 };
GetStartupPath(initial_dir);
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = file_mask;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = initial_dir;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER;
if (!GetSaveFileNameA(&ofn))
{
*error_code = GetLastError();
return;
}
char err_msg[1024] = { 0 };
std::string file_name = ofn.lpstrFile; //this stores path to file without extension
file_name.append(".");
file_name.append(ofn.lpstrDefExt); //this is NULL and fails to copy too
WriteAllBytes(file_name.c_str(), &file_data[0], file_data.size(), &err_msg[0]);
if (strlen(err_msg) > 0)
{
*error_code = GetLastError();
return;
}
}
I call it that way:
int write_error = 0;
PickupFileAndSave(compressed, &write_error, "RLE compressed files (*.rle)\0*.rle\0\0");
When I choose file it shows in the filter needed extension, but do not add it to lpstrFile.
Any ideas why and how to fix it?
You did not assign lpstrDefExt so the system will not add the extension in case you omit it. So you simply need to initialise the field before you show the dialog:
lpstrDefExt = "rle";
The documentation explains this:
lpstrDefExt
The default extension. GetOpenFileName and GetSaveFileName append this extension to the file name if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member is NULL and the user fails to type an extension, no extension is appended.
It's not clear from the code in the question but you want to handle the case where there are multiple filters and you wish to append the extension of the selected filter.
The system won't do that for you so you will have to. Read nFilterIndex after you have shown the dialog. That tells you which filter the user selected. Then parse the filter string to obtain the chosen extension, and append it to the filename if it has no extension.

Attempted to read or write protected memory when accessing dll

I try to access zip32.dll version 3.0 when my code got this error :
System.AccessViolationException: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
at projectName.clsName.ZpArchive(ZCL& zcl, ZPOPT& zopts)
at projectName.clsName.functionName() in <location>:<line>
This is what i done with the code :
//ZCL Structures
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
protected struct ZCL
{
public int argc; /* Count of files to zip */
[MarshalAs(UnmanagedType.LPStr)]
public string fzname; /* name of archive to create/update */
public string[] zipnames; /* zip file name */
[MarshalAs(UnmanagedType.LPStr)]
public string fzlist; /* name of archive to create/update */
}
//ZPOPT Structures
[ StructLayout( LayoutKind.Sequential )]
protected struct ZPOPT
{
[MarshalAs(UnmanagedType.LPTStr)]
public string Date; // US Date (8 Bytes Long) "12/31/98"?
[MarshalAs(UnmanagedType.LPTStr)]
public string szRootDir; // Root Directory Pathname (Up To 256 Bytes Long)
[MarshalAs(UnmanagedType.LPTStr)]
public string szTempDir; // Temp Directory Pathname (Up To 256 Bytes Long)
public int fTemp; // 1 If Temp dir Wanted, Else 0
public int fSuffix; // Include Suffixes (Not Yet Implemented!)
public int fEncrypt; // 1 If Encryption Wanted, Else 0
public int fSystem; // 1 To Include System/Hidden Files, Else 0
public int fVolume; // 1 If Storing Volume Label, Else 0
public int fExtra; // 1 If Excluding Extra Attributes, Else 0
public int fNoDirEntries; // 1 If Ignoring Directory Entries, Else 0
public int fExcludeDate; // 1 If Excluding Files Earlier Than Specified Date, Else 0
public int fIncludeDate; // 1 If Including Files Earlier Than Specified Date, Else 0
public int fVerbose; // 1 If Full Messages Wanted, Else 0
public int fQuiet; // 1 If Minimum Messages Wanted, Else 0
public int fCRLF_LF; // 1 If Translate CR/LF To LF, Else 0
public int fLF_CRLF; // 1 If Translate LF To CR/LF, Else 0
public int fJunkDir; // 1 If Junking Directory Names, Else 0
public int fGrow; // 1 If Allow Appending To Zip File, Else 0
public int fForce; // 1 If Making Entries Using DOS File Names, Else 0
public int fMove; // 1 If Deleting Files Added Or Updated, Else 0
public int fDeleteEntries; // 1 If Files Passed Have To Be Deleted, Else 0
public int fUpdate; // 1 If Updating Zip File-Overwrite Only If Newer, Else 0
public int fFreshen; // 1 If Freshing Zip File-Overwrite Only, Else 0
public int fJunkSFX; // 1 If Junking SFX Prefix, Else 0
public int fLatestTime; // 1 If Setting Zip File Time To Time Of Latest File In Archive, Else 0
public int fComment; // 1 If Putting Comment In Zip File, Else 0
public int fOffsets; // 1 If Updating Archive Offsets For SFX Files, Else 0
public int fPrivilege; // 1 If Not Saving Privileges, Else 0
public int fEncryption; // Read Only Property!!!
public int fRecurse; // 1 (-r), 2 (-R) If Recursing Into Sub-Directories, Else 0
public int fRepair; // 1 = Fix Archive, 2 = Try Harder To Fix, Else 0
public byte flevel; // Compression Level - 0 = Stored 6 = Default 9 = Max
[MarshalAs(UnmanagedType.LPTStr)]
public string fSplitSize; //Null for no spliting size
//addition for ZCL
public int m_CountFile; //For total file on backup file.
}
//Import Dll:
[DllImport("zip32.dll", SetLastError=true)]
protected static extern int ZpArchive(ref ZCL zcl,ref ZPOPT zopts);
And here's the function that call the ZpArchive :
//set the zip options
m_zopts = CreateZPOPTOptions();
ZCL zcl = new ZCL();
zcl.argc = m_CountFile; //Total file
zcl.fzname = m_ZipFileName;
zcl.zipnames = m_FilesToZip;
zcl.fzlist = null;
//zip the files
try
{
ret = ZpArchive(ref zcl,ref m_zopts);
}
catch(Exception e)
{
//<catch>
}
The exception threw when i try to call the ZpArchive function.
I'm using Visual Studio 2010 with compatibility for .Net 2.0
Any idea / advise regarding to this issue?
Thanks in advance :) -FDI
Update :
Here's the structure from library source code :
typedef struct { /* zip options */
LPSTR Date; /* Date to include after */
LPSTR szRootDir; /* Directory to use as base for zipping */
LPSTR szTempDir; /* Temporary directory used during zipping */
BOOL fTemp; /* Use temporary directory '-b' during zipping */
BOOL fSuffix; /* include suffixes (not implemented) */
BOOL fEncrypt; /* encrypt files */
BOOL fSystem; /* include system and hidden files */
BOOL fVolume; /* Include volume label */
BOOL fExtra; /* Exclude extra attributes */
BOOL fNoDirEntries; /* Do not add directory entries */
BOOL fExcludeDate; /* Exclude files newer than specified date */
BOOL fIncludeDate; /* Include only files newer than specified date */
BOOL fVerbose; /* Mention oddities in zip file structure */
BOOL fQuiet; /* Quiet operation */
BOOL fCRLF_LF; /* Translate CR/LF to LF */
BOOL fLF_CRLF; /* Translate LF to CR/LF */
BOOL fJunkDir; /* Junk directory names */
BOOL fGrow; /* Allow appending to a zip file */
BOOL fForce; /* Make entries using DOS names (k for Katz) */
BOOL fMove; /* Delete files added or updated in zip file */
BOOL fDeleteEntries; /* Delete files from zip file */
BOOL fUpdate; /* Update zip file--overwrite only if newer */
BOOL fFreshen; /* Freshen zip file--overwrite only */
BOOL fJunkSFX; /* Junk SFX prefix */
BOOL fLatestTime; /* Set zip file time to time of latest file in it */
BOOL fComment; /* Put comment in zip file */
BOOL fOffsets; /* Update archive offsets for SFX files */
BOOL fPrivilege; /* Use privileges (WIN32 only) */
BOOL fEncryption; /* TRUE if encryption supported, else FALSE.
this is a read only flag */
LPSTR szSplitSize; /* This string contains the size that you want to
split the archive into. i.e. 100 for 100 bytes,
2K for 2 k bytes, where K is 1024, m for meg
and g for gig. If this string is not NULL it
will automatically be assumed that you wish to
split an archive. */
LPSTR szIncludeList; /* Pointer to include file list string (for VB) */
long IncludeListCount; /* Count of file names in the include list array */
char **IncludeList; /* Pointer to include file list array. Note that the last
entry in the array must be NULL */
LPSTR szExcludeList; /* Pointer to exclude file list (for VB) */
long ExcludeListCount; /* Count of file names in the include list array */
char **ExcludeList; /* Pointer to exclude file list array. Note that the last
entry in the array must be NULL */
int fRecurse; /* Recurse into subdirectories. 1 => -r, 2 => -R */
int fRepair; /* Repair archive. 1 => -F, 2 => -FF */
char fLevel; /* Compression level (0 - 9) */
} ZPOPT, _far *LPZPOPT;
typedef struct {
int argc; /* Count of files to zip */
LPSTR lpszZipFN; /* name of archive to create/update */
char **FNV; /* array of file names to zip up */
LPSTR lpszAltFNL; /* pointer to a string containing a list of file
names to zip up, separated by whitespace. Intended
for use only by VB users, all others should set this
to NULL. */
} ZCL, _far *LPZCL;
and the function declaration :
int EXPENTRY ZpArchive(ZCL C, LPZPOPT Opts);
some forum said it's because of umanageable code. I already use MarshalAs but still not working..

Resources