2011-09-08 6 views
0
float latitude = [((IPADAppDelegate *)[UIApplication sharedApplication].delegate).detailViewController.userStoreInfoObj.StoreLatitude floatValue]; 
    float longitude = [((IPADAppDelegate *)[UIApplication sharedApplication].delegate).detailViewController.userStoreInfoObj.StoreLongitude floatValue]; 

    NSString *strAddress = [((IPADAppDelegate *)[UIApplication sharedApplication].delegate).detailViewController.userStoreInfoObj StoreAddress]; 
    NSString *strCountry= [((IPADAppDelegate *)[UIApplication sharedApplication].delegate).detailViewController.userStoreInfoObj StoreCounty]; 
    NSString *strCode = [((IPADAppDelegate *)[UIApplication sharedApplication].delegate).detailViewController.userStoreInfoObj StoreZip]; 

    if(storeData) 
    { 
     latitude = [storeInfoObj.StoreLatitude floatValue]; 
     longitude = [storeInfoObj.StoreLongitude floatValue]; 


     strAddress = [storeInfoObj StoreAddress]; 
     strCountry = [storeInfoObj StoreCounty]; 
     strCode = [storeInfoObj StoreZip]; 

    } 

초기화 중에 위도에 저장된 값은 읽히지 않습니다.값 초기화 중에 저장 됨

왜 이런 일이 일어 났는지 이해할 수 있습니까?

이 문제를 해결하려면 어떻게해야합니까? 제발 도와주세요 [나는 내 운을 시험해 본다]. 정적 분석기 가능성이 storeData 항상 true로 평가 것을 발견했습니다 :

+0

임무 코드가 있거나 다른 위치가 설정되었거나 storeData가 항상 true입니까? Analyzer를 실행하고 경고를 클릭하면 오류의 원인이되는 실행 경로가 표시됩니다. – zaph

+1

당신이 의미하는 바를 결코 읽을 수 없습니까? 나중에이 변수를 읽으려고 할 때 설정 한 초기 값이 제대로 설정되지 않은 것입니까? – Madhu

+0

@ Madhumal Gunetileke 실제로 응용 프로그램 에서이 경고를 발견 그래서 빌드 및 분석에서 실행중인 응용 프로그램. 그래서 내 프로젝트에 제로 경고와 제로 잠재 누수가있는 응용 프로그램을 원합니다 ... – user891268

답변

0

한 예 미리 감사드립니다 @

StoreData * storeData = thing.storeData; 
if (!storeData) { 
/* get out of here!!! */ 
    return; 
} 

IPADAppDelegate * appDelegate = (IPADAppDelegate*)[UIApplication sharedApplication].delegate; 
UserStoreInfoObj * userStoreInfoObj = appDelegate.detailViewController.userStoreInfoObj; 

float latitude = [userStoreInfoObj.StoreLatitude floatValue]; 
float longitude = [userStoreInfoObj.StoreLongitude floatValue]; 

NSString *strAddress = [userStoreInfoObj StoreAddress]; 
NSString *strCountry= [userStoreInfoObj StoreCounty]; 
NSString *strCode = [userStoreInfoObj StoreZip]; 


if (storeData) << would be redundant and always true 
{ 
    latitude = [storeInfoObj.StoreLatitude floatValue]; << why not initialize latitude using this value??? 
    longitude = [storeInfoObj.StoreLongitude floatValue]; 

    strAddress = [storeInfoObj StoreAddress]; 
    strCountry = [storeInfoObj StoreCounty]; 
    strCode = [storeInfoObj StoreZip]; 

} 

을하지만 크게이 프로그램의 복잡성을 줄일 수 있습니다 (읽기, 유지 및 실행)

UserStoreInfoObj * storeInfo = nil; 
if (storeData) storeInfo = storeInfoObj; 
else storeInfo = ((IPADAppDelegate *)[UIApplication sharedApplication].delegate).detailViewController.userStoreInfoObj; 

float latitude = [storeInfo.StoreLatitude floatValue]; 
float longitude = [storeInfo.StoreLongitude floatValue]; 

NSString *strAddress = [storeInfo StoreAddress]; 
NSString *strCountry= [storeInfo StoreCounty]; 
NSString *strCode = [storeInfo StoreZip];