0
我在將CCLocationManager方法轉換爲塊時遇到問題。 我CLLocationManager方法是這樣的:如何將CLLocationManager方法轉換爲iOS中的塊目標c
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
}
else{NSLog(@"current location is nil");};
}
我想這種方法轉換成塊,但在試圖這樣做有困難。一種新的客觀的C和IOS開發。
我在做什麼是這樣的:
double (^getSpeed)(*CLLocation, *CLLocation) = ^(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
mSpeed = currentLocation.speed;
}
else{NSLog(@"current location is nil");};
return mSpeed;
};
,但它給了我一個錯誤說,它預計在塊的第一行的表達式。這是什麼意思? 任何幫助,將不勝感激。
我同意但它不能返回任何東西。基本上我試圖在另一個函數中寫一個塊,它會返回給我一個速度 – Nik391
如果「didUpdateLocations」委託方法被調用「updateCurrentLocation」,則必須返回該位置。檢查代表是否正在呼叫。在塊中,它可以計算出你想要的速度。 – Vishnuvardhan
感謝您的澄清 – Nik391