小编San*_*nto的帖子

如何使用swift为字典中的一个键添加多个值

我一直在尝试为字典中的一个键添加多个值.

在目标c中,我们可以这样写:

NSDictionary *mapping = @{@"B": @[@"Bear", @"Buffalo"]};
Run Code Online (Sandbox Code Playgroud)

但是在Swift中我们怎么写我正在尝试这样但是它不能访问:

var animalsDic   = ["B": "Bear","Ball",
                "C": "Cat","Camel"
                "D": "Dog",
                "E": "Emu"]
Run Code Online (Sandbox Code Playgroud)

谁能帮我吗?.

swift

9
推荐指数
2
解决办法
2万
查看次数

没有箭头的UIPopoverPresentation

我试图提出一个UIViewController,UIPopoverPresentationController但我真的不喜欢箭头功能.

基本上我想要做的就是使用UIPopoverPresentationController without the arrow它附带的.

我在Swift编写代码.

iphone xcode uipopovercontroller ios swift

8
推荐指数
1
解决办法
4195
查看次数

如何使用RxSwift处理项目中的Disposables是否正确?

当我开始使用RxSwift时,我曾经BaseViewController使用RxSwift在我所有的控制器上创建和扩展它.BaseViewController.swift的代码:

class BaseViewController: UIViewController {
var mSubscriptions: CompositeDisposable?

func addSubscription(subscription: Disposable){
    if(mSubscriptions == nil){
        mSubscriptions = CompositeDisposable()
    }
    if let mSub = mSubscriptions{
        mSub.addDisposable(subscription)
    }
}

func unsubscribeAll(){
    if let mSub = mSubscriptions{
        mSub.dispose()
        mSubscriptions = nil
    }

}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    unsubscribeAll()
}

deinit{
    unsubscribeAll()
}
}
Run Code Online (Sandbox Code Playgroud)

我在我的子控制器中使用addSubscription(:_)方法.例如,一段代码来自:

class TasksViewController: BaseViewController{
   overrided func viewWillAppear(){
       //...
     var subscribe = dataLoader.load(requestNetwork, dataManager: taskDataManager)
    .observeOn(ConcurrentDispatchQueueScheduler(queue: queue))
    .subscribe({ (event) -> Void in
        //...

    }) …
Run Code Online (Sandbox Code Playgroud)

ios swift rx-swift

5
推荐指数
1
解决办法
2024
查看次数

如何从数组中获取唯一值

请注意,这适用于OSX,不适用于iOS.

我在其他SO问题中看过并尝试了一些解决方案,但似乎没有一个对我有用,因此:

我想从阵列中获得一组独特的年份.

我的代码是这样的:

NSMutableArray * unique = [NSMutableArray array];
        NSMutableSet * processed = [NSMutableSet set];
        for (yearString in yearStringArray) {
            if (![processed containsObject:yearString] == NO) {
                [unique addObject:yearString];
            }
            [processed addObject:yearString];
        }

        NSLog(@"unique: %@",unique );
        NSLog(@"processed: %@",processed );

    }];

The console returns:

unique: (
        (
        1941,
        1942,
        1943,
        1945,
        1948,
        1948,
        1948,
        1949
    )

processed: {(
        (
        1941,
        1942,
        1943,
        1945,
        1948,
        1948,
        1948,
        1949
    )
)}
Run Code Online (Sandbox Code Playgroud)

我只想要一个1948年.我将不胜感激任何帮助.

更新:感谢所有答案.让他们来吧!!!

这些是我现在尝试过的代码剪辑:

1.

for (yearString in yearStringArray) {
            if ([processed …
Run Code Online (Sandbox Code Playgroud)

macos objective-c nsarray nsset

4
推荐指数
2
解决办法
9920
查看次数

当app在后台时,将纬度和经度发送到服务器

我已经经历了这么多链接,即使在那之后我还没有找到适当的解决方案来获取经度和经度.

定期iOS后台位置更新

iOS长时间运行的后台计时器,带有"位置"后台模式

我尝试从一些链接和论坛,但它只工作3分钟,然后应用程序根本没有更新用户位置.

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


//create new uiBackgroundTask
__block UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    [app endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];

//and create new timer with async …
Run Code Online (Sandbox Code Playgroud)

background core-location nstimer ios

3
推荐指数
1
解决办法
6016
查看次数

从Objective C类的按钮操作加载基于Swift的ViewController

注意:对于任何问题,它都不是重复的.我找不到任何一些操作方法的问题,并为基于swift的视图控制器创建实例.

我在目标c类.m文件中调用基于swift的视图控制器.

在我的ViewController.m我已导入桥头

#import "ViewController.h"
#import "Project-Bridging-Header.h"
Run Code Online (Sandbox Code Playgroud)

我想从下面的动作调用基于Swift的视图控制器

- (IBAction)tappedButnGo:(UIButton *)sender {

     SwiftViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SwiftViewController"];
}
Run Code Online (Sandbox Code Playgroud)

我在这里得到一个错误

使用未声明的标识符SwiftViewController

以下是快速的课程

import UIKit

@objc class SwiftViewController: UIViewController {
 //so on
Run Code Online (Sandbox Code Playgroud)

而我BridgingHeader是空的.

SwiftViewController当我点击Objective C's按钮动作时,有人可以帮我装载吗?

action objective-c ios swift

3
推荐指数
2
解决办法
4269
查看次数

将Tableview放在UITableViewCell Swift中

我在将一个tableview放在一个uitableview单元格中时遇到了麻烦.现在,它甚至没有显示嵌套的tableview.我将tableview的委托和数据源设置为自定义单元格,并具有所有必需的方法.我也在为我的tableviews使用故事板,并正确连接所有插座.

问题是它没有进入cellforrow功能.但是,它确实进入了numberofrowinsection函数,以及heightforrow函数.下面是包含嵌套的uitableviewcell的自定义单元格的代码.

导入UIKit

class EventSurveyCell:UITableViewCell,UITableViewDelegate,UITableViewDataSource {

import UIKit

class EventSurveyCell: UITableViewCell, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var cellBox: UIView!
@IBOutlet weak var announcementLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var authorLabel: UILabel!
@IBOutlet weak var numVotesLabel: UILabel!
@IBOutlet weak var tableView: UITableView!
var surveyArray: [SurveyClass] = []

override func awakeFromNib() {
    super.awakeFromNib()
    tableView.delegate = self
    tableView.dataSource = self
    // Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    tableView.delegate …
Run Code Online (Sandbox Code Playgroud)

nested uitableview swift

1
推荐指数
1
解决办法
4803
查看次数

如何在ios中将此字符串转换为json或字典

我厌倦了链接,但那些在我的情况下不起作用.

任何人都可以建议我如何将此字符串转换为json或字典.

这个字符串有一个包含字符串数组的字典.

NSString *temp=@"{\n    name =     {\n        dob = \"\";\n        age = \"61\";\n        family =         (\n                        {\n                location = location;\n                mobile = mobile;\n            }\n        );\n    };\n}";
Run Code Online (Sandbox Code Playgroud)

这里的家庭是阵列.

json objective-c nsstring ios

-1
推荐指数
1
解决办法
7603
查看次数