如何nsuserdefault在swift中自动清除值?我已经尝试了这个,但它对我不起作用......
[[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]];
Run Code Online (Sandbox Code Playgroud) 在这里,我试图制作圆角矩形角进度条,但我有一些问题来创建它,在这里我发布我的代码我尝试了什么?
任何人都想让自定义进度条到圆角矩形进度条.
self.progressView.frame=CGRectMake(55, 490, 200, 15)
self.progressView.layer.cornerRadius = 15.0
self.progressView.transform=CGAffineTransformMakeScale(1.0, 7.0)
Run Code Online (Sandbox Code Playgroud) 我曾尝试将swift ViewController文件包含在Objective-C项目中,但我无法做到,它显示错误,如未知类型名称导入如何解决此问题请任何一个帮助解决此问题.
在这里,我发送我的代码和ScreenShot.
import UIKit
@objc class SigViewController2: UIViewController {
@IBOutlet weak var cameraBtn: UIButton!
@IBOutlet weak var imageBtn: UIButton!
@IBOutlet weak var settingsBtn: UIButton!
@IBOutlet weak var mediaBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
navigationController?.navigationBarHidden = false
self.navigationItem.title = "Main";
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
// Only allow Portrait
return UIInterfaceOrientationMask.Portrait
}
override func preferredInterfaceOrientationForPresentation() …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中实现了一些TextField功能所以我使用了TextField Delegates,但它显示了一些错误,如"字符串类型的值没有成员长度"我不知道如何解决这个问题,请帮助我解决这个问题.
在这里,我给出了我正在尝试的代码.
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
var oldLength: Int = textField.text!.characters.count
var replacementLength: Int = string.characters.count
var rangeLength: Int = range.length
var newLength: Int = oldLength - rangeLength + replacementLength
if textField.tag == 1 {
if string.length > 0 && !NSScanner.scannerWithString(string).scanInt(nil) { **------>//Error was showed in this line.**
return false
}
// This 'tabs' to next field when entering digits
if newLength == 5 {
if textField == txtOtp4 {
textField.resignFirstResponder() …Run Code Online (Sandbox Code Playgroud) 我会在我的应用程序中实现SearchBar概念,但它有一个错误,当我输入搜索栏中的第一个字符时它不工作而tableview没有显示相关字段,它显示空tableview但我输入第二个字符显示相关字段在tableview中,我不知道是什么错误让我请帮帮我.
我在这里给出了我的代码.
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
NSLog(@"searching::");
if(searchBar.text.length == 0)
{
[searchDict removeAllObjects];
[arrayDict removeAllObjects];
searchDict=[[NSMutableArray alloc]init];
arrayDict=[[NSMutableArray alloc]init];
[self getJsonResponse];
[self.tableView reloadData];
} else {
[arrayDict removeAllObjects];
arrayDict=[[NSMutableArray alloc]init];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self getSearchJsonResponse:searchBar.text];
NSLog(@"searchDict::%@",searchDict);
[self.tableView reloadData];
});
}
Run Code Online (Sandbox Code Playgroud) 当我在swift中将Json字符串转换为字典时,我得到了问题:错误域= NSCocoaErrorDomain Code = 3840"JSON文本没有以数组或对象开头,并且选项允许未设置片段." UserInfo = {NSDebugDescription = JSON文本不以数组或对象开头,并且选项允许未设置片段.}
我不知道要解决这个问题,请给出解决问题的想法.在这里,我给了我的代码我尝试了什么..
将Json字符串转换为字典的方法是,
func convertToDictionary(from text: String) throws -> [String: String] {
guard let data = text.data(using: .utf8) else { return [:] }
let anyResult: Any = try JSONSerialization.jsonObject(with: data, options: [])
return anyResult as? [String: String] ?? [:]
}
Run Code Online (Sandbox Code Playgroud)
Json字符串是: "[{\"propertyId\":\"1\",\"inspectionTemplateId\":1118,\"value\":[{\"widgetControllerId\":141,\"value\":\"Flood Summary Name\"},{\"widgetControllerId\":142,\"value\":\"Did the property flood?\"},{\"widgetControllerId\":143,\"value\":\"no\"}]}]"
方法的用法是:
let jsonString = NSString(data: responseObject as! Data, encoding: String.Encoding.utf8.rawValue)!
print(jsonString)
do {
let dictionary:NSDictionary = try self.convertToDictionary(from: jsonString as String) as NSDictionary …Run Code Online (Sandbox Code Playgroud) 我试图在TableView中查看MKMapView,但它已经崩溃了一些问题,但我无法找到问题,请任何人帮我清除这个问题?它显示这样......
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无效的区域中心:-119.27656620,+ 34.26884010 span:+0.04487346,-0.12825858>'
在这里,我给我的代码我做了什么..
let location = CLLocationCoordinate2D(
latitude: longarray[indexPath.row] as! Double,
longitude: latarray[indexPath.row] as! Double
)
print("the json array of Longitude is \(self.longarray[indexPath.row])")
print("the json array of Longitude is \(self.latarray[indexPath.row])")
let span = MKCoordinateSpanMake(2.0, 2.0)
print("the span is \(span)")
let region = MKCoordinateRegion(center: location, span: span)
cell.mapView.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = location
cell.mapView.addAnnotation(annotation)
Run Code Online (Sandbox Code Playgroud) 我想将BarCode Reader添加到我的项目中,但是当我尝试时我遇到了一些问题.在这里我给出了错误代码,如何解决这个请任何人帮我解决这个问题.
let dict = NSMutableDictionary()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict) //-----> In this line i have a error.
Run Code Online (Sandbox Code Playgroud) 在我的代码中,当我解析API时,我得到的错误就像__NSSingleObjectArrayI有nil,但是数组有值.
在这里,我给出了我的部分代码..
latitudeArray = [monumentArray valueForKey:@"lat"];
NSLog(@"latitudeArray is %@",latitudeArray);
longitudeArray = [monumentArray valueForKey:@"lng"];
NSLog(@"longitudeArray is %@",longitudeArray);
for (int i = 0; i<3; i++) {
CLLocation *locationA = [[CLLocation alloc] initWithLatitude:[latStr doubleValue] longitude:[longStr doubleValue]];
CLLocation *locationB = [[CLLocation alloc] initWithLatitude:[[latitudeArray objectAtIndex:i] doubleValue] longitude:[[longitudeArray objectAtIndex:i] doubleValue]]; ----------> This Line I Got The Crash Error..
CLLocationDistance distanceInMeters = [locationA distanceFromLocation:locationB];
NSLog(@"distanceInMeters is %f",distanceInMeters);
float i = distanceInMeters/1000;
NSLog(@"distance between two places is %f KM", i);
//[locationDistances addObject:distanceInMeters];
}
Run Code Online (Sandbox Code Playgroud)
NSSingleObjectArrayI是什么意思?
*** Terminating app due …Run Code Online (Sandbox Code Playgroud) 在此行中,错误是显示.有人能告诉我犯了什么错误吗?
Stripe.createTokenWithCard(card, completion: { (token: STPToken!, error: NSError!) -> Void in
self.handleToken(token)
Run Code Online (Sandbox Code Playgroud) 我必须根据文本的大小来扩展TextView的大小,但是它已经显示了问题,但是我无法修复,因此请帮助我解决此问题。
var size: CGSize = text.sizeWithFont(UIFont.boldSystemFontOfSize(13), constrainedToSize: textSize, lineBreakMode:NSLineBreakMode.ByWordWrapping)
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我实现了 FCM 推送通知。当使用 FCM 控制台和 pushtry.com 网站检查通知时,它工作正常,然后我尝试使用实际的服务器 API,前台通知运行良好,但后台通知未收到,有时它很少收到,而且没有横幅和声音。请帮助找出问题。
在这里,我附上了我正在尝试的代码。
import UIKit
import UserNotifications
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
return true …Run Code Online (Sandbox Code Playgroud) push-notification ios firebase swift firebase-cloud-messaging
swift ×10
ios ×6
firebase ×1
json ×1
objective-c ×1
string ×1
swift2 ×1
uifont ×1
uisearchbar ×1
uitableview ×1