Mac Newbie iPad 앱에 사용하기 위해 약 5,000 줄의 ANSI C를 Objective C로 변환해야합니다. 대부분의 코드는 아래 예와 비슷합니다. 시간을 절약하고 버그를 최소화하기 위해 Obj C로 이식하는 것이 절대적으로 필요한 경우에만 원래의 C 코드 만 변경하려고합니다. 변환을 이해할 수 있도록 아래의 코드 부분을 iPhone/iPad 사용자 인터페이스에 연결하기 위해 변경해야합니다 ? 모든 지침은 정말 감사하겠습니다. 도와 주셔서 감사합니다.ANSI C를 Objective C로 이식하는 데 필요한 최소 변경 사항은 무엇입니까?
void GetLandingSpeeds(LandingSpeeds *mySpeeds, int PhenomType, LandingInterpolationParameters *InterParams, char *FlapLand, char *WingStab)
{
mySpeeds->LandingSpeedsOK = No;
sprintf(query_string,"SELECT * FROM Landing_Speeds WHERE Weight = %d AND FlapLand = '%s' AND WingStab = '%s'", InterParams->Weight_lower, FlapLand, WingStab);
Query* GetFlapsSpeeds_Lower = sql_select_query(query_string, AircraftDatabase);
if (InterParams->Weight_Interpolation_Percent == 0)
{
// single table
if (GetFlapsSpeeds_Lower->RecordCount == 1)
{
mySpeeds->Vac = atoi(sql_item(GetFlapsSpeeds_Lower, "Vac"));
mySpeeds->Vref = atoi(sql_item(GetFlapsSpeeds_Lower, "Vref"));
if (PhenomType == P300)
mySpeeds->Vfs = atoi(sql_item(GetFlapsSpeeds_Lower, "Vfs"));
mySpeeds->LandingSpeedsOK = Yes;
}
}
else
{
// simple linear interpolation
sprintf(query_string,"SELECT * FROM Landing_Speeds WHERE Weight = %d AND FlapLand = '%s' AND WingStab = '%s'", InterParams->Weight_upper, FlapLand, WingStab);
Query* GetFlapsSpeeds_Upper = sql_select_query(query_string, AircraftDatabase);
if ((GetFlapsSpeeds_Lower->RecordCount == 1) && (GetFlapsSpeeds_Upper->RecordCount == 1))
{
mySpeeds->Vac = atoi(sql_item(GetFlapsSpeeds_Lower, "Vac")) * (1-InterParams->Weight_Interpolation_Percent) + atoi(sql_item(GetFlapsSpeeds_Upper, "Vac")) * InterParams->Weight_Interpolation_Percent;
mySpeeds->Vref = atoi(sql_item(GetFlapsSpeeds_Lower, "Vref")) * (1-InterParams->Weight_Interpolation_Percent) + atoi(sql_item(GetFlapsSpeeds_Upper, "Vref")) * InterParams->Weight_Interpolation_Percent;
if (PhenomType == P300)
mySpeeds->Vfs = atoi(sql_item(GetFlapsSpeeds_Lower, "Vfs")) * (1 - InterParams->Weight_Interpolation_Percent) + atoi(sql_item(GetFlapsSpeeds_Upper, "Vfs")) * InterParams->Weight_Interpolation_Percent;
mySpeeds->LandingSpeedsOK = Yes;
}
}
}
글쎄, 그냥 시작하고 있지만 올바른 구문을 사용하여 메서드를 함수를 변경해야합니다, 인스턴스화 된 변수, 등등 내 구조를 재구성 할. 나는 또한 SQL 쿼리를 다시 작성해야 할 것이라고 말했다. . C를 Obj C로 포팅하는 간단한 가이드를 찾고 싶습니다. – MonkeyBusiness
C를 Objective-C로 포팅 할 필요는 없습니다. Objective-C는 C의 상위 집합입니다. C로 수행 할 수있는 모든 작업은 Objective-C에서 변경없이 동일하게 실행됩니다. 나는 왜 당신이 SQL을 다시 작성해야하는지 상상할 수 없다. 그것은 C도 아니고 Objective-C도 아닙니다. SQL 백엔드를 변경하는 경우에만이 작업을 수행하면됩니다. 함수를 메서드로 변환하면 안됩니다. 메소드는 객체 지향 프로그래밍의 일부입니다. 메소드로 변환하는 경우 포트가 아닌 다시 설계해야합니다. 그러나 OOP를 원하지 않는 한, 그렇게 할 이유가 없습니다. –
Objective-C에서 Cocoa와 대화하는 것은 무엇이든 작성해야합니다. 즉, Objective-C에 UI를 명확하게 작성해야하지만, 이식성이있는 코드가 아니기 때문에 아무 것도 포트 할 필요가 없습니다. –