2011-09-08 63 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]; 

    } 

值初始化過程中存儲緯度是從來不看。價值的初始化過程中存儲到是沒讀過

任何人都可以幫助我理解爲什麼會發生這種情況嗎?

我能做些什麼來解決這個問題?請幫助我[我嘗試運氣]。

@在此先感謝

+0

是否有任務代碼,另一個地方是設置或是存儲數據總是爲真?運行分析器並單擊警告以查看導致錯誤的執行路徑。 – zaph

+1

你能否澄清你的意思是從來沒有讀過?你的意思是說,當你稍後嘗試讀取這個變量時,你設置的初始值似乎沒有被正確設置? – Madhu

+0

@ Madhumal Gunetileke其實iam在構建和分析中運行應用程序,所以我在我的應用程序中發現了這個警告。所以我想我的應用程序與零警告和零潛在泄漏的我的項目... – user891268

回答

0

一個例子:靜態分析可能已經檢測到storeData將始終評估爲真:

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]; 
相關問題