我使用Swift创建了一个小样本项目.我创建了一个"MyCustomView"作为xib,其中包含label,button和imageView,如下面的代码所示:
import UIKit
@IBDesignable class MyCustomView: UIView {
@IBOutlet weak var lblName: UILabel!
@IBOutlet weak var btnClick: UIButton!
@IBOutlet weak var myImageView: UIImageView!
var view:UIView!
@IBInspectable
var mytitleLabelText: String? {
get {
return lblName.text
}
set(mytitleLabelText) {
lblName.text = mytitleLabelText
}
}
@IBInspectable
var myCustomImage:UIImage? {
get {
return myImageView.image
}
set(myCustomImage) {
myImageView.image = myCustomImage
}
}
override init(frame : CGRect)
{
super.init(frame: frame)
xibSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
}
func xibSetup()
{
view …Run Code Online (Sandbox Code Playgroud) 我有情况在哪里我必须搜索**路由器**的IP地址,我知道它的范围是从范围163.289.2.0到163.289.2.255.我知道这不是搜索的好方法.
for i in 1... 255 {
var str = "163.289.2." + "i"
var tempIP = Ping.getIPAddress(str)
if(tempIP == true)
{
break;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我的自定义类Ping.getIPAddress()需要3秒才能获得给定IP值的结果.因此,对于255次搜索,大约需要765秒(12.75分钟).我有限制搜索应该在最多2分钟内完成.所以无论如何我可以使用swift在iPhone中实现这一点.
我必须只使用这个自定义函数Ping.getIPAddress(),如果存在给定的IP地址则为true,否则为false.
请提供解决此问题的示例或参考或方法.
使用NSOperationQueue和MaxConcurrentOperationCount设置为10会不错?
我在iPhone应用程序中使用Mobile snmp ++库(https://github.com/Zchander/mobile-snmp-plusplus/tree/master/Mobile%20SNMP%2B%2B)来使用swift语言扫描设备.
Mobile Snmp ++库是用Objective-C编写的,带有Bridging头我可以在我的swift项目中使用这个库,它可以很好地工作.
我需要从特定范围的ip地址扫描设备,假设170.23.45.0到170.23.45.255.为此,我使用XISMobile_SNMP_PP.mm的getoid函数(https://github.com/Zchander/mobile-snmp-plusplus/blob/master/Mobile%20SNMP%2B%2B/XISMobile_SNMP_PP.mm)
要从单个IP地址获得响应,每个响应大约需要1-2秒.为了减少时间,我使用多线程,如下面链接所示(由于我们将要使用该应用程序,因此最多只有20个线程在iphone中)从0到255完成扫描需要20秒.我需要将这个时间减少到大约5秒. 优化的方法来搜索iphone范围内的设备IP地址
问题:每次搜索开始时,getoid funtion都会打开套接字并发送数据,然后获得响应并关闭套接字.那么我们不能保持套接字打开,扫描所有的IP地址并让它重新启动并最后关闭套接字?我需要将搜索时间从20秒缩短到5秒,这样我们如何才能在getoid功能中完成.
- (NSDictionary *)getOid:(NSString *)oid
address:(NSString *)hostAddress
snmpVersion:(uint)version
remotePort:(NSNumber *)aPort
withCommunity:(NSString *)community
retry:(uint)retries
timeout:(uint)timeout
error:(NSError * __autoreleasing*)error
{
int status;
uint l_retries;
uint l_timeout;
NSNumber *localPort;
snmp_version snmpVersion = version1;
OctetStr snmpCommunity([community UTF8String]);
if ( aPort == nil ) {
localPort = [NSNumber numberWithInteger:161];
} else localPort = aPort;
if ( retries > 100 ) {
l_retries = 100;
} else …Run Code Online (Sandbox Code Playgroud) 我有一个小应用程序,可在iOS和tvOS上运行,并在UIView中显示视频。它确实支持iOS 12和tvOS 12。 ”。
即使部署目标设置为tvOS13。在Xcode中,功能->背景模式->启用了“音频,Airplay和画中画”。此基本代码给出了错误。
#import <AVKit/AVKit.h>
if ([AVPictureInPictureController isPictureInPictureSupported]) {
// code
}
Run Code Online (Sandbox Code Playgroud)
是否缺少其他设置或我需要做的其他事情?
谢谢
我有Windows应用程序在哪里我需要通过读取名为"Controls.txt"的文本文件在运行时填充枚举值. 作为限制,我不打算使用字典.以下是枚举MyControls中可用的默认值.我只能使用枚举.
public enum MyControls
{
Button1 = 0,
Button2 = 1,
Button3 = 2,
}
Run Code Online (Sandbox Code Playgroud)
如果Controls.txt文件可用,那么枚举的内容应该改变
public enum MyControls
{
btn1 = 0,
btn2 = 1,
btn3 = 2,
}
Run Code Online (Sandbox Code Playgroud)
最近我在电话采访中被问到了这个问题
"假设有3个相同长度的数组列表l1,l2和l3.三个线程访问三个列表.说T1 - > l1,T2 - > l2&T3 - > l3.它应按顺序打印说第1个元素的第一个元素然后第二个列表的第一个元素,然后是第三个列表的第一个元素.然后是第二个元素,第二个元素,第二个元素,第二个元素,第二个元素,第三个列表.
我回答说使用信号量可以解决这个问题,但是当我尝试使用信号量时,无法得到正确的答案.我的下面的代码出了什么问题
namespace Semaphore_Example
{
class Program
{
static List<int> list1 = new List<int>{ 1, 2, 3, 4, 5 };
static List<int> list2 = new List<int> { 1, 2, 3, 4, 5 };
static List<int> list3 = new List<int> { 1, 2, 3, 4, 5 };
static Semaphore semaphore = new Semaphore(0,3);
static SemaphoreSlim _sem = new SemaphoreSlim(3);
static void Main(string[] args)
{
Thread t1 = new Thread(show);
Thread t2 …Run Code Online (Sandbox Code Playgroud) 我创建了一个小型演示应用程序,其中该应用程序使用UIImagePickerController从iPhone访问图像和视频。当我选择任何图像或视频时,应用程序会在文档目录中创建其副本(图像或视频)。并使用GCDWebserver在iPhone上创建Web服务器,并需要公开所选的图像或视频。但这行不通。
这是示例代码,不确定我哪里可能出错。
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var btnselect: UIButton!
let videoPicker = UIImagePickerController()
@IBAction func btnSelect(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
let myPickerController = UIImagePickerController()
myPickerController.delegate = self;
myPickerController.sourceType = .photoLibrary
myPickerController.allowsEditing = false
self.present(myPickerController, animated: true, completion: nil)
}
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
self.dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
// 1. saving video to documents directory
let videoURL = info[UIImagePickerController.InfoKey.mediaURL] as! NSURL
let videoData …Run Code Online (Sandbox Code Playgroud) 我hava小窗口应用程序,用户输入代码和按钮单击事件代码在运行时编译.
当我第一次单击按钮时它工作正常,但如果多次单击相同的按钮,则会出现错误"进程无法访问Exmaple.pdb文件,因为它正由另一个进程使用." .下面是示例示例代码
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, "Example" + ".exe", true); //iloop.ToString() +
parameters.GenerateExecutable = true;
CompilerResults results = csc.CompileAssemblyFromSource(parameters,
@"using System.Linq;
class …Run Code Online (Sandbox Code Playgroud) 我有一个 iOS 应用程序,可以在 iPhone/iPad 设备上流式传输视频。
现在我需要在 iPhone/iPad 设备上获取视频流的比特率。
ObservedBitrate并IndicatedBitrate没有帮助。
我也在下面的帖子中看到了这篇文章,但很少有评论提到它仅适用于 mpeg4 视频。 如何在 iOS 中检查分辨率、视频比特率
我正在寻找 iPhone/iPad 上视频流的比特率和任何视频格式。
谢谢!
我真的不确定如何开始进行boost反序列化.下面是想要知道boost反序列化代码如何的示例代码.
#include <boost/serialization/access.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/smart_ptr/make_shared.hpp>
namespace mydata
{
struct MyInfo
{
std::string info = "extra info";
MyInfo(std::string info) : info(std::move(info)) {}
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int /*version*/)
{
ar & info;
}
};
struct MyData
{
std::string name;
std::string type;
boost::shared_ptr<MyInfo> myref;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int /*version*/)
{
ar & name;
ar & type;
ar & myref;
}
};
} …Run Code Online (Sandbox Code Playgroud) ios ×5
swift ×4
c# ×3
iphone ×3
search ×2
.net ×1
algorithm ×1
avfoundation ×1
avplayer ×1
avplayeritem ×1
boost ×1
c++ ×1
compilation ×1
dynamic ×1
enums ×1
gcdwebserver ×1
ioexception ×1
ios13 ×1
ipad ×1
objective-c ×1
runtime ×1
sockets ×1
tvos13 ×1
xib ×1